en.javascript.info/1-js/06-advanced-functions/07-settimeout-setinterval/4-settimeout-result/task.md
Ilya Kantor ab9ab64bd5 up
2017-03-21 14:41:49 +03:00

491 B

importance: 5


What will setTimeout show?

In the code below there's a setTimeout call scheduled, then a heavy calculation is run, that takes more than 100ms to finish.

When the scheduled function will run?

  1. After the loop.
  2. Before the loop.
  3. In the beginning of the loop.

What alert is going to show?

let i = 0;

setTimeout(() => alert(i), 100); // ?

// assume that the time to execute this function is >100ms
for(let j = 0; j < 100000000; j++) {
  i++; 
}