Skip to content

Latest commit

 

History

History
 
 

README.md

layout editorial
chapter 9
pageNumber 71
description An object is a composite data type that allows you to store and organize multiple values (properties) as key-value pairs. It is a fundamental data structure in the language and is widely used for representing complex data and creating structured entities.

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: