In JavaScript, an object is a collection of key-value pairs. Itβs used to store multiple values in a single variable, like a real-world entity with properties and behaviors.
car
object can have properties like brand
, model
, color
and methods like drive()
, brake()
.
let person = {
name: "John",
age: 30,
isStudent: false
};
person.name
β Dot notationperson["age"]
β Bracket notation
console.log(person.name);
console.log(person["age"]);
person.country = "India";
person.age = 31;
delete person.isStudent;
You can define functions inside objects:
let user = {
name: "Alice",
greet: function() {
return "Hello, " + this.name;
}
};
console.log(user.greet());
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!