Object Prototype

Prototypal Inheritance

W3Schools.com

Objects

Working with objects - JavaScript | MDN

Literals and properties

let user = {
	name: "John",
	age: 30 
};

To remove a property we can use the delete operator:

delete user.age;

We can also use multiword property names, but then they must be quoted:

let user = {
	name: "John",
	age: 30,
	"likes birds": true // multiword property name must be quoted
}

The last property in the list may end with a comma

let user = {
	name: "John",
	age: 30,
}

Square brackets

for multiword properties the dot access doesn’t work:

// this would give a syntax error
user.likes birds = true

There’s an alternative “square brackets notation” that works with any string:

let user = {};

// set
user["likes birds"] = true

// get
alert(user["likes birds"]); //true

// delete
delete user["likes birds"];
let key = "likes birds";

user[key] = true;
user.key //invalid syntax

Computed properties