← Lesson
BitWithBite
JavaScript · Quick Reference

Lesson 9 — Objects Cheat Sheet

JavaScript
In one line: An object is a collection of key-value pairs. Keys are strings (or Symbols), and values can be any data type.

Key Ideas

1Object Literals & Property Access. An object is a collection of key-value pairs. Keys are strings (or Symbols), and values can be any data type.
2Methods & The this Keyword. Object methods are functions stored as property values. Inside a method, this refers to the object the method belongs to.

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...