What is the output of this code? + EXPLAINE | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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])

12th Aug 2021, 5:54 PM
Ofir Salem
2 Answers
+ 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
12th Aug 2021, 6:00 PM
AĶ¢J
AĶ¢J - avatar
+ 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
12th Aug 2021, 6:02 PM
Abhay
Abhay - avatar