While trying to answer this question, I met a weird behavior (which isn't the same: his is due to too few iterations, mine to too much):
HTML:
<button id="go">it will be legend...</button>
<div id="output"></div>
JS:
var output = document.getElementById('output');
document.getElementById('go').onclick = function() {
output.textContent += 'wait for it...';
for (var i=0; i<3000000000; i++) {
var unused = i; // don't really care
}
output.textContent += ' dary!';
};
The loop takes few seconds to execute, because of its 3,000,000,000 iterations.
Once the button is clicked, what I expected:
wait for it...
appears- the process freezes a little bit because of the loop
dary!
appears
What actually happened:
- the process freezes a little bit because of the loop
wait for it... dary!
appears together
Any idea why such a behavior?
Check by yourself: fiddle.