In all the books/materials that I’ve read, they talk about in universal, absolute terms that all instances of an object inherit and have access to methods of the prototype the object was created from. For the most part, this seems generally true. But this doesn’t seem to be as universal as I have read. A simple example:
The length property is undefined for the objects that are typeof number.
For example:
x = 5;
typeof x;
=> returns number
number.length
=> returns undefined
I understand that it wouldn’t make much sense for a number to have a length (though I suppose it could reflect the number of digits in the number), the part that bothers me is that everything I’ve ready talks about this absolute principle of inheritance. And since everything is derived from the built-in Object, and even the built-in Number object has the length property, why would that property not be accessible in the example above for x?
The symbol
Numberrefers to the number constructor, not a prototype object. All functions have a “.length” property, giving the number of formal parameters in the function declaration. TheNumberbuiltin is indeed an object, as you say, but in particular it’s a function (an instance ofFunction).There’s no “length” property of
Number.prototype, which is why instances have no such property. (You can of course add one to any instance, or to the prototype, if you want to.)