Code Examples
// Object literal
const user = {
name: 'Ali',
age: 25,
email: 'ali@example.com',
isAdmin: false
};
// Dot notation (preferred when key is known)
user.name; // 'Ali'
user.age; // 25
// Bracket notation (when key is dyna...
const person = {
name: 'Sara',
age: 28,
// Method using regular function (this works!)
greet() {
return `Hello, I'm ${this.name}!`;
},
getInfo() {
return `${this.name} is ${this.age} years old.`;
},
haveBirthday() {
th...
const product = {
id: 42,
name: 'Keyboard',
price: 75,
brand: 'Logitech'
};
// Basic destructuring
const { name, price } = product;
// name='Keyboard', price=75
// Rename while destructuring
const { name: productName, price: cost } = p...