Object
In JavaScript, object is the only non-primitive type, and its values are mutable collections of properties that map keys to values. The Object global object supplies its constructor and static methods, and every value that isn’t a primitive is an object:
> { name: "Ada", born: 1815 }
{ name: 'Ada', born: 1815 }
> typeof { name: "Ada" }
'object'
Objects are mutable, so properties can be added, changed, and deleted after an object is created. They compare by reference: === and Object.is() return true only when both operands are the same object, whatever their contents.
object Literals and typeof
An object literal lists properties inside braces and supports shorthand properties, methods, computed keys in brackets, and spread syntax. Property keys are always strings or symbols, so a number used as a key becomes a string:
> const id = Symbol("id");
undefined
> const lamp = { name: "lamp", 42: "aisle", [id]: 7 };
undefined
> Object.keys(lamp)
[ '42', 'name' ]
> lamp[id]
7
Arrays, functions, dates, and class instances are objects too. The typeof operator reports 'object' for all of them except functions, which report 'function' because they’re callable. Array.isArray() is the reliable check for arrays:
> typeof []
'object'
> typeof new Date()
'object'
> typeof function () {}
'function'
> Array.isArray([])
true
typeof null also returns 'object', even though null is a primitive.
Creating Objects
Besides literals, objects come from calling a constructor or class with new and from Object.create(), which sets the new object’s prototype. Property lookups that miss on the object itself continue along that prototype link:
> const animal = {
… describe() {
… return `${this.name} is an animal`;
… },
… };
undefined
> const cat = Object.create(animal);
undefined
> cat.name = "Tom";
'Tom'
> cat.describe()
'Tom is an animal'
> Object.getPrototypeOf(cat) === animal
true
> new Map() instanceof Object
true
Key Static Methods and Properties
| Member | Kind | Description |
|---|---|---|
Object.keys(), Object.values(), Object.entries() |
Static method | Return arrays of own enumerable keys, values, or [key, value] pairs |
Object.fromEntries() |
Static method | Builds an object from [key, value] pairs, such as a Map |
Object.assign() |
Static method | Copies own enumerable properties onto a target and returns it |
Object.create() |
Static method | Creates an object with a given prototype, or none when passed null |
Object.groupBy() |
Static method | Groups iterable items into an object by a callback’s result (ES2024) |
Object.hasOwn() |
Static method | Returns whether a key is an own property (ES2022) |
Object.freeze(), Object.isFrozen() |
Static method | Make every property read-only and block additions and deletions, or check for it |
Object.seal(), Object.preventExtensions() |
Static method | Block adding and deleting properties, or only adding |
Object.defineProperty(), Object.getOwnPropertyDescriptor() |
Static method | Define a property from a descriptor, or read one back |
Object.getPrototypeOf(), Object.setPrototypeOf() |
Static method | Return or replace an object’s prototype |
Object.is() |
Static method | Compares like ===, but NaN equals itself and 0 differs from -0 |
Key Instance Methods and Properties
Objects inherit these from Object.prototype unless created with a null prototype:
| Member | Kind | Description |
|---|---|---|
.hasOwnProperty() |
Instance method | Returns whether a key is an own property |
.isPrototypeOf() |
Instance method | Returns whether the object is in another object’s prototype chain |
.toString() |
Instance method | Returns "[object Object]" unless a subclass overrides it |
.valueOf() |
Instance method | Returns the object itself unless a subclass overrides it |
.constructor |
Instance property | Refers to the function that created the object |
Converting Objects to Primitives
When an operation needs a primitive, JavaScript calls the object’s [Symbol.toPrimitive]() method with a hint. Unary + passes "number", template literals and String() pass "string", and binary + and == pass "default".
Without that method, JavaScript calls .valueOf() and then .toString(), or .toString() first for the "string" hint, and uses the first primitive result. A plain object’s .valueOf() returns the object itself, so conversion falls through to the inherited .toString() method:
> String({})
'[object Object]'
> `${[1, 2]}`
'1,2'
> const temperature = {
… [Symbol.toPrimitive](hint) {
… return hint === "number" ? 21 : "21 degrees";
… },
… };
undefined
> +temperature
21
> `${temperature}`
'21 degrees'
Every object is truthy, including empty objects, empty arrays, and new Boolean(false). The one exception is the legacy browser object document.all, which ECMA-262 allows hosts to treat as falsy.
Common object Gotchas
Two objects with identical contents aren’t equal, because comparison checks identity:
> {} === {}
false
> [1, 2] === [1, 2]
false
Spread syntax makes a shallow copy, so nested objects stay shared. The host-provided structuredClone() function, defined in the HTML Standard and available in browsers and server runtimes, copies them deeply:
> const settings = { theme: { color: "dark" } };
undefined
> ({ ...settings }).theme === settings.theme
true
> structuredClone(settings).theme === settings.theme
false
Declaring an object with const fixes the binding, not the object, so its properties can still change unless Object.freeze() locks them. Freezing is shallow, so nested objects stay mutable.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 4, 2026