Destructuring in javascript

Syedsufiyan
2 min readJun 27, 2020

--

in this article we will see what is destructuring in JavaScript , in destructring the values will be extracted from JavaScript object.

The Old Way

Older way was like this const client object use destructuring when you want extract values from an object

const client = {

name: ‘Alexa’,

membership: ‘Premium’

}

old way is : name = client.name,

membership = client.membership;

if console.log(name);

console.log(membership);

The New Way

if this object have 100 properties this have to create 100 of variables, so

lets introduce the new way

we will reuse same object client as before, so the way to access using destructuring is

let {name, membership} = client

console.log(name);

console.log(membership);

this was basic object destructing in JavaScript.

thank you for reading.

--

--