This commit is contained in:
Ilya Kantor 2016-11-14 16:31:21 +03:00
parent 3defacc09d
commit f99574f53b
178 changed files with 530 additions and 271 deletions

View file

@ -0,0 +1,15 @@
Any `setTimeout` will run only after the current code has finished.
The `i` will be the last one: `100000000`.
```js run
let i = 0;
setTimeout(() => alert(i), 100); // 100000000
// assume that the time to execute this function is >100ms
for(let j = 0; j < 100000000; j++) {
i++;
}
```

View file

@ -0,0 +1,27 @@
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?
```js
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++;
}
```