0
Why is d=4 in this code
let a, b, c = 4, d = 8; [a, b = 6] = [2]; // a = 2, b = 6 [c, d] = [d, c]; // c = 8, d = 4
4 odpowiedzi
+ 2
[a, b = 6] = [2];
2 is assigned to a, and because it has no second value, b stays 6
[c, d] = [d, c];
It just switches the values of c and d
c was 4, and d was 8, so c == 8 and d == 4
+ 1
Only at the end of the line, the values are assigned. So c becomes d (which is 8), then d becomes c (which is 4). Then both are assigned so they have switched values
0
Please Airree what is the reason for the switches. Thanks
0
Okay thanks