Defining properties

ES6 brought in a shorter syntax for assigning object properties to the values of variables that have the same name as the properties. Traditionally, you would've done this:

var x = 1, y = 2;var object = { x: x, y: y };console.log(object.x); //output "1"

But now, you can do it this way:

let x = 1, y = 2;let object = { x, y };console.log(object.x); //output "1"

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.