After diving into the tutorials here, I find myself struggling to grasp some elements of this example. Why is the variable initialized as an empty string and what does the ,i signify?
var x="",i;
Furthermore, why the need for
x=x
at the start of the line?
<!DOCTYPE html>
<html>
<body>
<p>Press the button to iterate from 1 to 6, creating HTML headings.</p>
<button onclick="myFunction()">Try it</button>
<div id="demo"></div>
<script>
function myFunction()
{
var x="",i;
for (i=1; i<=6; i++)
{
x=x + "<h" + i + ">Heading " + i + "</h" + i + ">";
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>