+ 1
What is the output of this code? + EXPLAINE
var arr=[10,20,30,40,50]; var a, b, c; [a, b, ...c]=arr; Console.log(c[1])
2 Antworten
+ 3
Ofir Salem
Triple dot (...) Means spread operator and it contains rest elements so here
a = 10
b = 20
And rest elements will go with c because of ...c
So here c is [30, 40, 50]
Now c[1] is 40
+ 2
[a, b,...c]=arr is destructuring of array where a is assigned value 10 ,b is assigned value 20 and c is assigned the array of values 30,40,50 by the help of rest syntax(...variable)
https://javascript.info/rest-parameters-spread