Member-only story
Javascript Understanding Destructuring in ES6
With the advent of ES6 in javascript we got lots of cool features. some of them are arrow function, map,filter, reducer and destructuring of object and Array etc.
When we talk About destructing in javascript. we have to talk about
1)Object Destructing
2) Array Destructuring
So Basically Destructuring is a new feature introduced in ES6 to unpack values from arrays or properties from an object. It helps in improving the readability and performance of our code.
Lets understand how it is to use properties or Array value before destructuring and after destructuring
ES5 Implementation
// Example 1 - Object Destructuring var user = {
name : 'krishankant singhal',
username : 'krishankant',
password : 12345
} const name = user.name; // krishankant singhal
const username = user.username; // krishankant
const password = user.password // 12345 //Example 2 - Array Destructing const fruits = ["apple", "mango", "banana", "grapes"]; const fruit1 = fruits[0];
const fruit2 = fruits[1];
const fruit3 = fruits[2];
ES6 Implementation using Destructuring Syntax
// Example 1 - Object Destructuring var user = {
name : 'krishankant…