Reputation: 1764
From the following code:
let n = 1234.567;
console.log(Object.getOwnPropertyNames(Number.prototype));
console.log(Object.getPrototypeOf(n));
console.log(Object.getPrototypeOf(5));
The first console.log
prints the properties, but the second and third line just print {}
. Why is this so? Is there a name to directly inspect the variable or number without having to refer to the base type, such as Number.prototype
?
Upvotes: 0
Views: 30
Reputation: 370679
The second and third line only appear to print empty objects due to how the Stack Snippet console operates - the actual browser console of Chrome, Firefox, Safari, or whatever browser you wish will be much more informative. When debugging things and logging objects, if you want the most informative interface, use the actual browser console.
Both of those lines really do point to Number.prototype
:
console.log(
Object.getPrototypeOf(5) === Number.prototype
);
Upvotes: 1