J

JavaScript Objects & Prototypes

Explore object creation, property access, methods, prototypes, and the prototype chain interactively.

Programming v1.0.0 5 uses
Step 1 of 6

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

Key
Value
name
"Alice" (string)
age
30 (number)
greet
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 notationperson.name — the most common way to access properties
  • Bracket notationperson["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

Objects are the building blocks of JavaScript. In this lab, you'll learn to create objects with literals and constructors, access and modify properties, understand methods and 'this', explore the prototype chain, and use Object.create and classes — all with live code editors and visual diagrams.

How It Works

  1. 1 Read each step's explanation of object concepts
  2. 2 Write code in the interactive editors
  3. 3 Inspect objects in the visual property inspector
  4. 4 Trace the prototype chain
  5. 5 Complete the quiz to test your understanding
ESC