event loop in javascript
The Event Loop has one simple job — to monitor the Call Stack
and the Callback Queue
3.5
4
The Event Loop has one simple job — to monitor the Call Stack
and the Callback Queue. If the Call Stack is empty, it will
take the first event from the queue and will push it to the
Call Stack, which effectively runs it. Such an iteration is
called a tick in the Event Loop. Each event is just a function
callback.
#bpn
Thank you!
4
0
3.67
3
console.log('Hi!');
setTimeout(() => {
console.log('Execute immediately.');
}, 0);
console.log('Bye!');
// print order
// 'Hi!'
// 'Bye!'
// 'Execute immediately.'
Thank you!
3
0
4.14
7
console.log('Hi!');
setTimeout(() => {
console.log('Execute immediately.');
}, 0);
console.log('Bye!');
Code language: JavaScript (javascript)
Thank you!
7
0
0
0
function task(message) {
// emulate time consuming task
let n = 10000000000;
while (n > 0){
n--;
}
console.log(message);
}
console.log('Start script...');
task('Download a file.');
console.log('Done!');
Code language: JavaScript (javascript)
Thank you!
0
0
Are there any code examples left?
New code examples in category Javascript