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 are collections of key-value pairs, or properties. The keys can be Strings or Symbols, and values are either primitives (numbers, strings, symbols) or references to other objects.

In JavaScript, a significant amount of values are objects (e.g. functions, arrays) or primitives that behave as immutable objects (numbers, strings, booleans). Their properties or their prototype’s properties can be accessed using dot (obj.prop) or bracket (obj['prop']) notation. Notable exceptions are the special values undefined and null.

Objects are held by reference in JavaScript, not by value. This means that when copied or passed as arguments to functions, the “copy” and the original are references to the same object, and a change to one’s properties will change the same property of the other. This does not apply to primitives, which are immutable and passed by value.

Shallow cloning

Object.freeze

Object cloning

Object properties iteration

Object.assign

Object rest / spread (...)

Accessor properties get and set

Convert objects values to 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