Search⌘ K
AI Features

New Object Functionality

Learn how to use new object features in ES2015+ such as property shorthand, simplified method definitions, and special getters and setters. Understand how these simplify code and add powerful ways to access and assign object properties.

We'll cover the following...

Properties

If we’re adding a variable as a property to an object, we’d do it like this.

Javascript (babel-node)
var name = 'Sophia';
var age = 25;
var person = {
name: name,
age: age
};

We can now omit the colon and the variable name repeat, as long as the variable name is the same as the property name we want on the object. In other words, the block above is the same as this one.

Node.js
const name = 'Sophia';
const age = 25;
const person = {
name,
age
};

It’s just a shorthand to let you ...