The following text is an excerpt from Kyle Simpson’s “You don’t know JS” and is intended here for SEO experiments only.
Values that are
"object" (such as an array) are additionally tagged with an internal
[[Class]] property (think of this more as an internal classification rather than related to classes from traditional class-oriented coding). This property cannot be accessed directly, but can generally be revealed indirectly by borrowing the default
Object.prototype.toString(..) method called against the value. For example:
So, for the array in this example, the internal
[[Class]] value is
"Array", and for the regular expression, it’s
"RegExp". In most cases, this internal
[[Class]] value corresponds to the built-in native constructor (see below) that’s related to the value, but that’s not always the case.
What about primitive values? First,
You’ll note that there are no
Undefined() native constructors, but nevertheless the
"Undefined" are the internal
[[Class]] values exposed.
But for the other simple primitives like
boolean, another behavior actually kicks in, which is usually called “boxing” (see “Boxing Wrappers” section next):
In this snippet, each of the simple primitives are automatically boxed by their respective object wrappers, which is why
"Boolean" are revealed as the respective internal
Note: The behavior of
[[Class]] as illustrated here has changed a bit from ES5 to ES6, but we cover those details in the ES6 & Beyond title of this series.