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. using object.create

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

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

In this chapter, we will explore following topics:

results matching ""

    No results matching ""