4 Answers
+ 7
Lets take it step by step.. let [learn, solo] = "learn"; This destructures "l" into `learn` and "e" into `solo`. The fact that the `solo` variable has a default value, like let [learn, solo = "solo"] = ... does not matter, since there are enough letters in your string to fill both variables. This line [solo, learn] = [learn, solo]; is the same as [solo, learn] = ["l", "e"]; It destructures "l" into `solo` and "e" into `learn`. The last line simply adds "l" and "e" together.
10th Aug 2020, 10:25 PM
Schindlabua
Schindlabua - avatar
+ 6
đŸ†‡đŸ†ˆđŸ…Œ//Inactive It can have an effect, if the string is too short. Consider this: let [learn, solo = "banana"] = "X"; Here `learn` obviously gets the "X", but then we have no more letters to give to `solo`. So, `solo` would keep it's default value of "banana". But in the challenge question there are enough letters, so `solo` gets overwritten so to say :)
10th Aug 2020, 10:34 PM
Schindlabua
Schindlabua - avatar
+ 5
Schindlabua so it's not possible to pass on a value in destructucturing ? Like here : solo="solo" Has no effect?
10th Aug 2020, 10:30 PM
xym
xym - avatar
+ 5
Schindlabua okay, I understood, Thank you very much Sir
10th Aug 2020, 10:49 PM
xym
xym - avatar