I was just reading YDKJS up and going. And here are something I wanna understand.
In JavaScript there are 5 primitive types: undefined, null, boolean, string and number. Everything else is an object.
Which means that the all the 5 primitive types of value are immutable. But, object is mutable.
The primitive types boolean, string and number can be wrapped by their object counterparts.
Which means that we can do something like this:
true;
Boolean(true);
But can we do something like this?
true;
Number(true);
However here is an example I found online and here are some of my questions:
typeof true; //"boolean"
typeof Boolean(true); //"boolean"
typeof new Boolean(true); //"object"
typeof (new Boolean(true)).valueOf(); //"boolean"
I don’t understand the last two line of code. What does it mean? Is new Boolean(true);
a function? And the last line of the code, why it returns “boolean” ?? Could someone explain what does all these mean?