ES6-Destructuring

Destructuring is much less complicated than it sounds. It's a shorthand way to pull variables and their associated values out of objects and arrays.

by manoj_antony32

CSS

/* Destructuring is much less complicated than it sounds. It's a shorthand way to pull variables and their associated values out of objects and arrays. In JavaScript ES5, you'd have to write out the name of the object you're pulling the values from each time you wanted to create a new variable. */

JavaScript

var randomData = {a: 12, b: false, c: 'blue'};
var {b, a} = randomData;

/* console.log(a)
console.log(b)
 */
var x = {name: 'mano', age: 25};

function test({name, age}) { //another way of destructuring
  console.log(name, age)
}

test(x)