Destructuring

var {color, position} = {
color: "blue",
name: "hemant",
state: "USA",
position: "UI Dev"
};
console.log(color, position); // blue UI Dev

Use Case 1

function generateObj(){
return {
color: "blue",
name: "hemant",
state: "USA",
position: "UI Dev"
};
}
var {name, state} = generateObj();
console.log(name, state); // hemant USA

rename variable name

function generateObj(){
return {
color: "blue",
name: "Paa",
state: "India",
position: "UI Dev"
};
}
var {name:firstName, state: location} = generateObj();
console.log(firstName, location); // Paa India

Use Case 2

var [first,,,,last] = [1,2,3,4,5];
console.log(first, last); // 1 5

Use Case 3

var friends = [
{
name: "Hemant",
location: "Hyd",
status: "Cool",
},
{
name: "Vinay",
location: "USA",
status: "NOO",
}
];
friends.forEach(function({name, email}){
console.log(name +", "+ email);
});
// output
Hemant, [email protected].com