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:
literal
let object = {}; // Yes, simply a pair of curly braces!
Note: this is the recommended way.
object-oriented
let object = new Object();
Note: it's almost like Java.
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: