Javascript.PrimitiveValue


Although "everything in Javascript is an Object", this is not quite true, in the case of "primitive values", which are basic data items not wrapped in the usual Javascript Object infrastructure. This is done for performance reasons.

In the case of a simple boolean value, that can contain only "true" and "false" values, which can themselves be represented by a single bit (1/8th of a byte, on most systems), it is wasteful to set up an hierarchy of prototypes, instance methods etc.

So when you do:

  var happy = true;

The Javascript run-time engine has the opportunity to store this value as an optimized primitive system type, rather than a full-fledged object. Until some kind of "wrapping" operation happens, these kind of raw values do not allow doing things like calling methods like so:

  var happy = true;
  // should not technically work...
  wisdom.console.log(happy.toString());
  // except that it does, because the javascript engine 
  // performs an auto-wrapping for us.

This is part of the SpineFORGE Reference Documentation for Javascript?