Daniel Richardson3,148 Points
Why the empty string in var html?
Hi I don't fully understand the purpose of the empty string in the html variable
I've tested removing
= ''; from
var html the script still runs but the page shows "undefined" at the start of the number list.
Can someone explain to me why this happens?
Many Thanks Dan
Jennifer NordellTreehouse Staff
Hi there! Yes, when you say
var html; this creates a variable named
html but at this point the value is
undefined. Later, when you try concatenating on to it it takes
undefined and then concatenates on to the end. This is why the
undefined is showing up. However, if you start by declaring the
var html = ''; then the original value is not undefinedd, but rather an empty string and you can concatenate onto it as much as you like
Hope this helps!