true is a boolean primitive - that is, "boolean" with lowercase "b". This is not an object.
Similarly, "hello" not an instance of String, because the string primitive is also not an object.
You can check primitive types using the typeof operator.
The distinction between primitive values ββand object values ββcan get a little confused in JavaScript, because the language implicitly wraps primitives in the corresponding wrappers of objects when primitives are used as references to objects. That is why you can write
var length = "hello world".length;
The string is implicitly converted to an instance of String for this operation . for work. You can do this with boolean:
var trueString = true.toString();
This also happens with numbers, although the syntax sometimes gets in the way:
var failure = 2.toString();
source share