Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Going Further
Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Going Further
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
I can get the value of a specific property from an object
I can use dot notation to access object properties
I can use bracket notation to access object properties
I know which notation is preferred for accessing object properties
Code Editor
Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.
Console Output
0 output lines