Objects
suggest changeSyntax
- object = { }
- object = new Object()
- object = Object.create(prototype[, propertiesObject])
- object.key = value
- object["key"] = value
- object[Symbol()] = value
- object = { key1: value1, "key2": value2, 'key3': value3 }
- object = { conciseMethod() { … } }
- object = { [computed() + "key"]: value }
- Object.defineProperty(obj, propertyName, propertyDescriptor)
- property_desc = Object.getOwnPropertyDescriptor(obj, propertyName)
- Object.freeze(obj)
- Object.seal(obj)
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.
Accessor properties get and set
Convert an object's values to an array
Dynamic variable property names
Retrieving properties from an object
Descriptors and Named Properties
Object.getOwnPropertyDescriptor
Properties with special characters or reserved words
Iterating entries with Object.entries