freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../es6/use-destructuring-assignmen.../index.md

13 lines
423 B
Markdown
Raw Normal View History

2018-10-12 19:37:13 +00:00
---
title: Use Destructuring Assignment to Assign Variables from Arrays
---
## Use Destructuring Assignment to Assign Variables from Arrays
We have to take some precaution in this case.
1. No need of const [b,a] as it will keep the effect of assignment local.
2. const [b,a] = [a,b] will result in the value of a,b as undefined(simple assignment rule left to right).
Hence the solution to this problem is
[b,a] = [a,b]