+ 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

9th Jun 2020, 6:15 AM
Olivia Munn 🙋🤷‍♀
Olivia Munn 🙋🤷‍♀ - avatar
2 Antworten
+ 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/
9th Jun 2020, 6:22 AM
Gordon
Gordon - avatar
+ 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.
17th Jun 2020, 7:17 AM
moses
moses - avatar