“Qu'est-ce que la boucle d'événement en javascript” Réponses codées

boucle d'événement

Event Loop : The event loop is the secret behind JavaScript's asynchronous 
programming. JS executes all operations on a single thread, but using a 
few smart data structures, it gives us the illusion of multi-threading.

Easy Definition : 
The Event Loop has one simple job — to monitor the Call Stack and the 
Callback Queue or Message Queue. 

If the Call Stack is empty, it will take the first event from the
Callback 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.

Easiest explanation : 
When any Asynchronous event occur such as setTimeOut or promises... 
Then these task takes some time to complete I/O if they have any. 
If they completed their I/O or don't have any, then they simply put into 
message queue or callback queue. Then event loop will firstly execute the 
call stack tasks and then look for callback or message queue and then execute it..

For more info visit : https://nodejs.dev/learn/the-nodejs-event-loop
Excited Emu

Qu'est-ce que la boucle d'événement en javascript

The Event Loop has one simple job — to monitor the Call Stack 
and the Callback Queue
Odd Ox

boucle d'événement javascript

         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)
Aqeel

boucle d'événement javascript

console.log('Hi!');

setTimeout(() => {
    console.log('Execute immediately.');
}, 0);

console.log('Bye!');

// print order
// 'Hi!'
// 'Bye!'
// 'Execute immediately.'
Clever Caiman

boucle d'événement javascript

function foo(b) {
  let a = 10
  return a + b + 11
}

function bar(x) {
  let y = 3
  return foo(x * y)
}

const baz = bar(7) // assigns 42 to baz
Ahsan Mustafa

Réponses similaires à “Qu'est-ce que la boucle d'événement en javascript”

Questions similaires à “Qu'est-ce que la boucle d'événement en javascript”

Plus de réponses similaires à “Qu'est-ce que la boucle d'événement en javascript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code