Essential JavaScript

Accessing Properties

After we create an object, we will probably need to check or update its individual properties.

We can do that using dot notation:

const person = {
  name: 'John Doe',
  age: 22,
};

console.log(person.name);
console.log(person.age);

Another way to access and update properties is by using bracket notation:

const person = {
  name: 'John Doe',
  age: 22,
};

console.log(person['name']);
console.log(person['age']);

Most of the time dot notation is easier to read and type. However, there are times when dot notation won't work and bracket notation is necessary:

  • If a property has a space or other special character in its name (don't do this on purpose)
  • If a property name is a number

We will practice using bracket notation later. For now, remember to always use dot notation if possible.


Learning Goals

Code Editor