Next →

Objects in JavaScript

Objects let you group related data and functionality into key–value pairs. Each property has a name (key) and a value.

Creating an Object

let person = {
name: "Alice",
age: 25,
job: "Developer"
};

Accessing Properties

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

Changing Properties

person.age = 26;

Adding New Properties

person.country = "USA";

Methods Inside Objects

let car = {
	brand: "Toyota",
	drive: function() {
		console.log("Vroom!");
	}
};

car.drive();