typeof Number(2); // but it's actually an object!
Similarly, primitive values are not instances of these constructor functions:
2 instanceof Number;
In fact, the two things are not strictly equal:
Number(2) === 2;
Primitives are actually without their own methods. The primitive wrapper
objects Number , String , and Boolean are used in the background to
provide primitive values with methods. When a method is called on a prim-
verts it into an object and then calls the method on the object. This means
that it is possible to call methods on primitives such as we saw in Chapter 2:
2..toExponential(); // remember 2 dots to call
In the background, something similar to this is happening:
Even custom objects that we've created have a toString() method:
<< "[object Object]"
It may convey little information, but it does return a string representation of the object.
Search WWH ::