Getting Started with JavaScript for Web Development


More Details on Objects

When I state that "everything is an object", that is an oversimplification. A more apt description would be:

Everything can become an object.

There are primitives (strings, numbers, and booleans) and objects (String, Number, and Boolean). For instance:

// primitives
const primitiveString = 'my string';
const primitiveNum   = 47;

// objects
const myObjString = String('my string');
const myObjNum   = Number(47);

JavaScript has the ability to convert on the fly from the primitives, to the objects, and back to the primitive when the need arises.

JavaScript will wrap the primitive in its object counterpart so that we can use the methods like .toLowerCase().

Like this article? Follow @chrisoncode on Twitter