destructuring assignment mdn code example

Example 1: Object destructuring

Object Destructuring =>
//
   The destructuring assignment syntax is a JavaScript expression that makes it
possible to unpack values from arrays,
or properties from objects, into distinct variables.
//
example:
const user = {
    id: 42,
    is_verified: true
};

const {id, is_verified} = user;

console.log(id); // 42
console.log(is_verified); // true

Example 2: mdn destructuring

const x = [1, 2, 3, 4, 5];
const [y, z] = x;
console.log(y); // 1
console.log(z); // 2

Example 3: mdn destructuring

let a, b;

[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2

Example 4: js object destructuring

const { [propName]: identifier } = expression;