Chapter 9

Objects

In javascript the objects are mutable because we change the values pointed by the reference object, instead, when we change a primitive value we are changing its reference which now is pointing to the new value and so primitive are immutable. The primitive types of JavaScript are true, false, numbers, strings, null and undefined. Every other value is an object. Objects contain propertyName: propertyValue pairs. There are three ways to create an object in JavaScript:

  1. literal

    let object = {};
    // Yes, simply a pair of curly braces!
    

    Note: this is the recommended way.

  2. object-oriented

    let object = new Object();
    

    Note: it's almost like Java.

  3. and using object.create

    let object = Object.create(proto[, propertiesObject]);
    

    Note: it creates a new object with the specified prototype object and properties.

results matching ""

    No results matching ""