FAQ: Introduction to JavaScript - Properties

Hello, what would the .length for numbers be, I tried assigning a variable to a number and then putting the variable in the console.log but it returns undefined, thanks fairly new to this.

Numbers are exact values that don’t have a length. Sure they have numeral characters, etc., but as objects they have no length. Further to this, numbers are not iterable.

“When you introduce a new piece of data into a JavaScript program, the browser saves it as an instance of the data type”

Can somebody please explain this concept in simpler terms? Thank you very much

a = 42

Above we assign an integer value (a number) to the variable, a. When we poll the type of a we are actually polling the type of 42. a is not an object, but a reference to an object. 42 is identified by the interpreter as being a number type so gives it a wrapper object of that type.

typeof 42  =>  'number'

typeof a   =>  'number'

So a refers to an instance of a number type.

1 Like

I think I understand it better now, thank you for your explanation sir.

1 Like