I'm a 24 years old programming enthusiast. I have tons of ideas but i honestly give up on many before giving them any chances, i guess like many others before me :)
The way I see it you are constantly overwriting that value. For each item in the array you are assigning it to the same variable. By adding the += you are basically saying “hey add this value to my variable” instead of “hey assign this value to my variable”.
Assigning something means no matter what you had there before, it will now point to the new value you chose (this is achieved by using = ). The += is instead looking at what you have there and adds your new value to that, concatenating it.
I know it’s not a very technical explanation but I hope it does help.
Thank you so much! Your reply helped me a bunch. And I am also grateful for the non-technical explanation. I have a hard time understanding when the reply is too "techy" so thank you! I really appreciate it.
I'm a 24 years old programming enthusiast. I have tons of ideas but i honestly give up on many before giving them any chances, i guess like many others before me :)
The way I see it you are constantly overwriting that value. For each item in the array you are assigning it to the same variable. By adding the += you are basically saying “hey add this value to my variable” instead of “hey assign this value to my variable”.
Assigning something means no matter what you had there before, it will now point to the new value you chose (this is achieved by using = ). The += is instead looking at what you have there and adds your new value to that, concatenating it.
I know it’s not a very technical explanation but I hope it does help.
Thank you so much! Your reply helped me a bunch. And I am also grateful for the non-technical explanation. I have a hard time understanding when the reply is too "techy" so thank you! I really appreciate it.
No problem, glad i could help 😁
👆 Exactly this.
=
replaces what is currently ininnerHTML
+=
appends more information toinnerHTML
Breaking this down a bit further:
is shorthand for:
So whenever you call the
+=
line, you're adding an<li>
to your existinginnerHTML
instead of replacing it (which is the case with=
)