I want to know what is considered an object in javascript so that I can answer the simple question of whether the number literal 1 (or any other literal) is an object.
I tried these
typeof 1
> "number"
1 instanceof Number
> false
Number(1) instanceof Number
> false
Number(1) instanceof Object
> false
Number instanceof Object
> true
new Number(1) instanceof Object
> true
new Number(1) instanceof Number
>true
(1).constructor
> ƒ Number() { [native code] }
(1).constructor.constructor
> ƒ Function() { [native code] }
(1).constructor.constructor.constructor
> ƒ Function() { [native code] }
(1).constructor.constructor.constructor.constructor
> ƒ Function() { [native code] }
Function instanceof Object
> true
1 === Number(1)
> true
1 === new Number(1)
> false
(1).constructor
> ƒ Number() { [native code] }
(new Number(1)).constructor
> ƒ Number() { [native code] }
Number.constructor
> ƒ Function() { [native code] }
Function instanceof Object
> true
So... can anyone tell me if this question can even be answered?
How does javascript differentiate between the literal 1 and the new Number(1)
if they have the same constructor? Does JS just lie to me that they have the same constructor?
What's an object even? Probably it doesn't matter, but I'm curious whether this has some sort of rule-based answer.
Can anyone guide me through what I'm seeing? Because what makes sense to me is that there are differing object hierarchies in Javascript, and JS is lying to me about the constructors of the literals...