I have some trouble understanding what happens during this for loop. I can imagine the function cycles, as in the value of "text" is changed five times. But when I imagine how it works, shouldn't the output of this whole block of code be 9? Because first, "text" changed its value five times, ending at 9, and then the document. part was executed. But the output is 1 3 5 7 9. Can someone explain what really happens?
var text = "";
var i;
for (i = 1; i < 10; i = i + 2) {
text += i + "<br>";
}
document.getElementById("demo").innerHTML = text;