+ 22
Please explain this (JavaScript) code.
let [learn, solo = "solo"] = "learn"; console.log(solo); // output: e console.log(learn); // output: l How solo = e & learn = l
2 Answers
+ 17
When you perform ES6 array destructuring, the string is splitted into an array of characters.
So the first character is stored in learn
So the second character is stored in solo
https://www.sololearn.com/learn/JavaScript/2977/
+ 1
learn is the first part of the array so it refers to the first letter of the string 'learn' and then solo is the second part of the array with the index 1 so it will take the value of the second letter of the string.