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

2nd Jun 2019, 5:06 PM
Confy Sir confy
Confy Sir confy - avatar
4 Respuestas
+ 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
2nd Jun 2019, 5:10 PM
Airree
Airree - avatar
+ 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
2nd Jun 2019, 5:21 PM
Airree
Airree - avatar
0
Please Airree what is the reason for the switches. Thanks
2nd Jun 2019, 5:19 PM
Confy Sir confy
Confy Sir confy - avatar
0
Okay thanks
2nd Jun 2019, 5:22 PM
Confy Sir confy
Confy Sir confy - avatar