“Was ist Ereignisschleife in JavaScript?” Code-Antworten

Ereignisschleife

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

Was ist Ereignisschleife in JavaScript?

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

JavaScript -Ereignisschleife

         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

Event Loop JavaScript

console.log('Hi!');

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

console.log('Bye!');

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

JavaScript -Ereignisschleife

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

Ähnliche Antworten wie “Was ist Ereignisschleife in JavaScript?”

Fragen ähnlich wie “Was ist Ereignisschleife in JavaScript?”

Weitere verwandte Antworten zu “Was ist Ereignisschleife in JavaScript?” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen