Javascript event loop

Javascript

1. Single threaded

2. Non-blocking

3. Asynchronous concurrent language

How does Javascript works ?

1. Javascript Engine

2. Event loop

3. Callback queue

4. Web APIs

Visualisation of callstack

function f1(a){
   return 21 * a;
}

function f2(){
   return f1(2);
}

function print(){
   const res = f2();
   console.log('res: ', res)
}

print();
const x_res = syncReq('x.com')
const y_res = syncReq('y.com')
const z_res = syncReq('z.com')

console.log(x_res);
console.log(y_res);
console.log(z_res);

How to prevent this situation ?

Asynchronous callback

console.log('Hi');

setTimeout(function() {
    console.log('there');
}, 5000)

console.log('Gndg meetup');

Thanks

email : sumanshweta44@gmail.com

event loop

By shweta suman

event loop

  • 580