Objects

suggest change

Syntax

Parameters

Property Description
value The value to assign to the property.
writable Whether the value of the property can be changed or not.
enumerable Whether the property will be enumerated in for...in loops or not.
configurable Whether it will be possible to redefine the property descriptor or not.
get A function to be called that will return the value of the property.
set A function to be called when the property is assigned a value.

Objects contain properties. Each property key is a string or symbol, and its value can be any JavaScript value.

Functions, arrays, maps, sets, and dates are specialized objects. Strings, numbers, booleans, bigints, symbols, null, and undefined are primitives. Property access on most primitives temporarily boxes the value, but primitives do not become mutable objects. Property access on null or undefined throws a TypeError.

JavaScript always passes and assigns values. For an object value, that value is a reference: copying it makes another reference to the same object, so mutations through either reference are visible through the other. Reassigning one variable does not reassign the other. Primitive values are immutable and are copied directly.

Shallow cloning

Object.freeze

Object cloning

Object property iteration

Object.assign

Object rest / spread (...)

Accessor properties get and set

Convert an object's values to an array

Dynamic variable property names

Arrays are Objects

Object.defineProperty

Object.seal

Retrieving properties from an object

Object.keys

Descriptors and Named Properties

Object.getOwnPropertyDescriptor

Lock property description

Non enumerable property

Read-only property

Creating an iterable object

Properties with special characters or reserved words

Iterating entries with Object.entries

Object.values

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents