Saturday, 14 April, 2018 UTC


Summary

  • It’s a JavaScript expression that allows us to extract data from arrays, objects, maps and sets.
  • Sometimes you need top level variables like so: – const person = { – first: ‘Ashish’, – last: ‘Patel’, – country: ‘India’, – city: ‘Bhopal’, – twitter: ‘@ashishpatel0720’ – }; – const first = person.first; – const last = person.last;You’ve to write this code over and over again, where we…
  • What we could do instead of creating multiple variables, we destructure them in a single line like so: – const { first, last } = person;It’s the new destructuring syntax.
  • The above code says, give me a variable called first, a variable called last, and take it from the person object.
  • Array destructuring: – Array destructuring is exactly same as Object destructing – var x = [1, 2, 3, 4, 5]; – var [y, z] = x; – console.log(y); // 1 – console.log(z); // 2It is not necessary to get values sequencially, we skip some values as well, – var x…
Along with arrow functions, let, and const, destructuring is probably something you’re going to be using every single day. What does destructuring mean? It’s a JavaScript expression that allows us to…
@ashishpatel0720: I just published “Simple introduction to Destructuring in JavaScript/ES6/ES2015”
#es6…
Simple introduction to Destructuring in JavaScript/ES6/ES2015Along with arrow functions, let, and const, destructuring is probably something you’re going to be using every single day.
What does destructuring mean? It’s a JavaScript expression that allows us to extract data from arrays, objects, maps and sets.
Let’s take a look at what problem JavaScript destructuring really solves. Sometimes you need top level variables like so:
const person = {
first: ‘Ashish’,
last: ‘Patel’,
country: ‘India’,
city: ‘Bhopal’,
twitter: ‘@ashishpatel0720’
};
const first = person.first;
const last = person.last;You’ve to write this code over and over again, where we need to make a variable from something that is inside of an object or inside of an array. What we could do instead of creating multiple variables, we destructure them in a single line like so:
const { first, last } = person;It’s the new destructuring syntax.
The above code says, give me a variable called first, a variable called last, and take it from the person object. We’re taking the first property and the lastproperty and putting them into two new variables.
Array destructuring:
Array destructuring is exactly same as Object destructing
var x = [1, 2, 3, 4, 5];
var [y, z] = x;
console.log(y); // 1
console.log(z); // 2It is not necessary to…
Simple introduction to Destructuring in JavaScript/ES6/ES2015