Bug in your Code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Bug in your Code?

This sample code seems to have a bug. After the first line, a and b are 'undefined'. Is that the intention? ES6 Destructuring: The destructuring syntax also simplifies assignment and swapping values: let a, b, c = 4, d = 8; [a, b = 6] = [2]; // a = 2, b = 6 [c, d] = [d, c]; // c = 8, d = 4

22nd Apr 2020, 10:34 PM
John Weiss
John Weiss - avatar
3 Answers
+ 2
Yes, unlike c and d they aren't given a value until the 2nd line which is 1 example of using destructuring. 3rd line is another example.
22nd Apr 2020, 10:40 PM
ChaoticDawg
ChaoticDawg - avatar
22nd Apr 2020, 10:47 PM
BroFar
BroFar - avatar
+ 2
there is no bug
25th Apr 2020, 1:51 PM
Gordon
Gordon - avatar