Accessing Properties

Reading object properties.

Examples

Dot Notation

Accessing property using a dot.

const person = {firstName:"John", lastName:"Doe"};
console.log(person.firstName);

Bracket Notation

Accessing property using brackets (useful for dynamic keys).

const person = {firstName:"John", lastName:"Doe"};
console.log(person["lastName"]);

Dynamic Access

Using a variable to access a property.

const person = {age: 30};
let key = "age";
console.log(person[key]); // 30

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.