Update event-loop.md

This commit is contained in:
xfarrow 2024-08-06 12:39:43 +02:00
parent 22cc0e4260
commit 0adc594656

View File

@ -7,17 +7,24 @@ flow of execution. Whenever we meet a portion of code that may not be
possible to execute now, it is put in the Event Loop. Let's look at some possible to execute now, it is put in the Event Loop. Let's look at some
examples: examples:
1. ```javascript 1.
setTimeout(() => console.log('test'), 1000);
``` ```javascript
`console.log('test')` will be put in the Event Loop.
setTimeout(() => console.log('test'), 1000);
```
console.log('test') will be put in the Event Loop.
2.
```javascript
2. ```javascript
const promise = new Promise(function (resolve, reject) { const promise = new Promise(function (resolve, reject) {
console.log('test'); console.log('test');
resolve(); resolve();
}).then(() => { }).then(() => {
console.log('test2'); console.log('test2');
}); });
``` ```
`console.log('test2')` will be put in the Event Loop. console.log('test2') will be put in the Event Loop.