Empty quotes assigned to variable - explanation (solved)

Empty quotes assigned to variable - explanation (solved)


Ok, so here is the exercise:

Could anyone explain, since I don’t recall it being explained anywhere, how var output = ""; works? Are the empty quotation marks just placeholders - we use them just to indicate that the result will be a string, or something else? Could anyone elaborate how this works, and in which occasions should we use it?

Also, I don’t understand completely this code:output += "myGlobal: " + myGlobal;, since this is the same as output = output + "myGlobal: " + myGlobal; . If that’s true, how "" + "myGlobal" + 10 === myGlobal: 10 ?


It tells you that the output is expected to be a string. This is a good practice in my opinion because you could do it several ways.

As for this :

output += "myGlobal: " + myGlobal;


output = output + "myGlobal: " + myGlobal;

The first one use a shorthand (+=) which does exactly as the second statement. it adds the current value of the left hand assignement with the right side, so saying this :

output += value;

is like saying :

output = output + value;


This is a great explanation, all that was unclear you have cleared out, thank you so much!