Skip to content

Object

In one line

An object is a collection of key-value pairs that groups related data and behavior under a single name.

In simple words

An object is like a container with labeled compartments. Each compartment (key) holds a value, and you use the label to find what is inside. For example, a person object might have a name key holding "Ada" and an age key holding 36.

Objects are the primary way to represent real-world entities in code. Instead of having separate variables personName, personAge, personEmail, you group them into one person object with properties name, age, email.

In JavaScript, objects are created with curly braces and use string keys. In Python, the equivalent is a dictionary (dict). In Java, you define a class and create instances. The concept is the same: named properties grouping related data.

Example

javascript
const person = {
  name: "Ada",
  age: 36,
  email: "[email protected]"
};

console.log(person.name);  // "Ada"
console.log(person.age);   // 36

The person object has three properties. You access each value using dot notation with the key name.

Common confusions

  • Confused with: array

    The difference: An object uses named keys to access values; an array uses numeric indices. Objects are for named properties; arrays are for ordered lists.

  • Confused with: class

    The difference: A class is a blueprint/template for creating objects. An object is a specific instance created from a class (or created directly as a literal).

Related terms

Related Resources

Related Lessons

  • Objects

    Learn how objects work in programming.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary