Es6 destructuring operator in JavaScript

JavaScript from es6 enables destructuring operation,

In JavaScript destructuring is done using the syntax;

const [elements] = [array]
const {properties} = {object}

For instance using Math object as an example destructuring can be done as follows;

Object matching syntax;

const {abs, min, max} = Math;

List matching syntax;

const [max, min, avg] = [10, 1, 5]

Fail-soft destructuring similar to object property look up returns undefined if there's no property matching;

var [item] = [];
item === undefined;

Fail-soft destructuring can also be done with predefined default vslues as follows;

var [item = 1] = [];
item === 1;

More information:


Popular posts from this blog

Open-graph meta data tags introdution

What is 'this.' keyword in JavaScript

How to create zip archives in nodejs

what is 'array.includes' function in JavaScript

How to build a twitter retweet bot using JavaScript