+ 3
4 Respuestas
+ 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.
+ 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 :)
+ 5
Schindlabua so it's not possible to pass on a value in destructucturing ?
Like here : solo="solo"
Has no effect?
+ 5
Schindlabua okay, I understood,
Thank you very much Sir