Course contentsShow
← JavaScript
Lesson 593 of 2,72315. ObjectsFree lesson

Property Values Can Be Any Type

Store primitives, objects, arrays, and functions as property values.

Property Values Can Be Any Type

You'll learn that object properties aren't limited to simple values—they can hold anything JavaScript supports.

The Core Idea

So far, you've seen objects with simple property values like strings and numbers. But JavaScript doesn't restrict you here. Any valid JavaScript value can be stored as a property: primitives (numbers, strings, booleans, null, undefined), other objects, arrays, and even functions.

Think of an object like a filing cabinet. Each drawer (property) can hold whatever you need—a single document (primitive), a folder of documents (array), another filing cabinet (nested object), or even a tool (function) that does something when you open it.

Examples in Plain English

const user = {
  name: "Alice",                    // string
  age: 30,                          // number
  isActive: true,                   // boolean
  address: {                        // nested object
    city: "Portland",
    zip: 97201
  },
  hobbies: ["reading", "cycling"],  // array
  greet: function() {               // function
    console.log("Hello!");
  }
};

You can access these just like any other property:

user.name;           // "Alice"
user.address.city;   // "Portland"
user.hobbies[0];     // "reading"
user.greet();        // Logs "Hello!"

When a function is stored as a property, we often call it a method of that object.

Why This Matters

This flexibility makes objects incredibly powerful for modeling real-world entities. A user object can contain both data (strings, numbers) and behavior (functions), along with structured collections (arrays) and related information (nested objects).

Key Takeaway: Object properties accept any JavaScript value—primitives, objects, arrays, or functions—giving you complete flexibility in how you structure your data.