So far, you have primarily worked with the following data types:
(See more in Section 1.5)
These are all primitive data types. They form the building blocks of more complex data types in Javascript, called objects. Any data type that is not a primitive type is classified as an object.
Recall from Section 1.5 and Section 5.5 that Objects have properties that come in key:value pairs:
let myCubeObject = {
sideLength: 8;
color: “yellow”;
}
That’s all we know about objects so far. What makes objects so different from primitives? Are they a collection of primitive data types (like in the example above, myCubeObject store two values in primitive data types)? Objects are far more complex and have many more functions than primitives. For example, objects may have methods:
let myCubeObject = {
sideLength: 8;
sayHi() {
console.log(“Hi!”);
}
}
We may call the sayHi method in the following way:
myCubeObject.sayHi();
What exactly is going on behind the scenes when we create and use objects? This has to do with the object prototype chain, which we’ll explore in the next section.