May 2019
Beginner to intermediate
650 pages
14h 50m
English
An object is an unordered collection of data. Values in an object are stored as key-value pairs. You can create an object by declaring a comma-separated list of key:value pairs within curly braces, or simply a pair of opening-closing curly braces if you want to start with an empty object:
const color = {name: "red", code: ff0000};const empty = {};
Objects can contain other objects and arrays, which can also contain objects. They can also contain functions (which have access to local properties and behave as methods):
const city = {name: "Sao Paulo", location: {latitude: 23.555, longitude: 46.63}, airports: ["SAO","CGH","GRU","VCP"]};const circle = { x: 200, y: 100, r: 50, area: function() { return this.r * this.r * 3.14; }Read now
Unlock full access