JavaScript Objects & Prototypes
Explore object creation, property access, methods, prototypes, and the prototype chain interactively.
Step 1: What are Objects?
In JavaScript, an object is a collection of key-value pairs. Each pair is called a property. When a property's value is a function, it is called a method.
Objects are the most fundamental data structure in JavaScript — arrays, functions, dates, and even regular expressions are all objects under the hood.
Object Literal: person
"Alice" (string)30 (number)function() (method)Key terms:
- Property — a key-value pair stored in an object
- Key — the name (always a string or Symbol) that identifies a property
- Value — the data stored under a key (any type: string, number, array, object, function, etc.)
- Method — a property whose value is a function
- Dot notation —
person.name— the most common way to access properties - Bracket notation —
person["name"]— required when keys have spaces or are dynamic
// Creating an object with an object literal
const person = {
name: "Alice",
age: 30,
greet: function() {
return "Hi, I'm " + this.name;
}
};
// Accessing properties
person.name; // "Alice" (dot notation)
person["age"]; // 30 (bracket notation)
person.greet(); // "Hi, I'm Alice"
About This Lab
How It Works
- 1 Read each step's explanation of object concepts
- 2 Write code in the interactive editors
- 3 Inspect objects in the visual property inspector
- 4 Trace the prototype chain
- 5 Complete the quiz to test your understanding
More Labs in Programming
JavaScript Promises & Async
ProgrammingMaster asynchronous JavaScript — callbacks, Promises, async/await, and error handling with visual timelines.
Git Fundamentals
ProgrammingLearn the core Git workflow — staging, committing, branching, and merging through an interactive terminal simulator.
Array Methods in JavaScript
ProgrammingMaster map, filter, reduce, and more — transform arrays with live code exercises and visual diagrams.