Search⌘ K
AI Features

Objects

Explore JavaScript objects, including creation, adding and accessing properties, and mutability. Understand arrays and built-in objects like Date. Gain skills to manipulate object properties using dot and bracket notation, and recognize object mutability for effective programming.

Introduction

Almost everything in JavaScript is made up of objects. These are all the non-primitive types.

They include arrays, dates, and almost everything non-primitive. They are mutable values in JavaScript. To access their property or data, use . or [] operators.

How do we create these objects?

Creating objects

Objects are created using the {} operator. If we assign a variable to {}, we have an object with no properties.

Node.js
var obj = {}; // Declare our object
//print value and type of obj
console.log('Our object:',obj);
console.log('Type of our object:',typeof(obj));

On line 1, we created our first object and assigned it to the variable obj. On the lines that follow, see how it is printed and its type, nothing fancy so far.

Adding and modifying properties

While declaring or after declaring an object, we can assign and modify the properties of an object. A ...