is keyed collections of various data (not primitive - single value)
object references and copying
store and copied by reference (not like primitive data types)
a variable is assigned to object stores reference (address in memory) instead of object itself
const object’s attributes can be modified
const a = { name: "Peter" };const b = a; // copy a's properties by referencesconst c = {};for (const [k, v] in Object.entries(a)) c[k] = v; // clone, it's copy references if any attribute of a is object -> deep clone
garbage collection
counted by incomming references make an object is reachable
this keyword
is not bounded -> can be used in any function, even if it’s not class’ function
this is evaluated during runtime, depends on the context
arrow functions don’t have this, it takes from outer context
classes
can return from constructor, and methods can be defined in constructor
function User(name) { // this = {}; this.name = name; this.isAdmin = false; // return this;}const user = new User("Dat"); // create new object
optional chaining ’?’
for non existing properties, support shorten chaining
promise.then(...).then(...).then(...); // chaining - handlers process sequentially// handlers process independentlypromise.then(...);promise.then(...);
async/await
special syntax to work with promises
async function() returns a promise, wraps non-promises in it
await promise makes JS wait until that promise settles and returns its result (suspends the function execution to wait and resume)