Smart coding: destructuring in JavaScript
Destructuring assignment is the best one that came with latest JS features.
We can make our code look smart. Just take a look at the following:
js
const Person = {name: 'AshKeys',blog: 'ashokma.com'}const { name, blog } = Personconsole.log(`${name} - ${blog}`)
Isn't this lovely! \O/
We can do the same for arrays as well.
js
const [max, min] = [80, 20]console.log(`Min - ${min}; Max - ${max}`)
We can swap values using the same.
[a, b] = [b, a]