reference types
JS ⟩ value ⟩ object
an unordered collection of properties (name : value pairs).
inherits properties of another object, known as it's prototype.
any value that is not primitive is an object.
// creating objects {name: value} // object literal new Object() // `new` statement let obj = Object.create(prototype) // specify an object's prototype
🈯 synonyms: "hash", "hashtable", "dictionary", "associated array".
most common things to do with objects:
create objects.
access (get/set, delete / test / enumerate) their properties.
🔰 creating objects
object literal / new / Object.create()
🔰 accessing properties
property access expression
dot notation (.) / bracket notation []
optional chaining (?., ?.[]) / optional invocation ?.()
delete / test / enumerate properties
🔰 extending objects
Object.assign() - copies properties from other objects.
mixin
inheritance
prototype
prototype chain
🔰 converting objects
serializing objects - convert/restore object's state to/from string.
.toString() / .toLacaleString() - object -> string.
.valueOf() - object -> primitive (typically a number)
.toJSON() - a method expected by JSON.stringify()
use optional chaining (?., ?.[]) to safely acess object's members.
literal
event handler can be an object.
the import in import.meta is NOT an object❗️
JS object is associated array.
ExploringJS ⟩ 14. New OOP features besides classes
JavaScript: The Definitive Guide ⟩ Ch. 6 Object
MDN ⟩ JavaScript ⟩
JavaScript Guide ⟩ Working with objects
built-in objects ⟩
Object
Function
Proxy
accessor property
Last updated 2 years ago