“Что такое цикл событий в JavaScript” Ответ

петля мероприятия

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

Что такое цикл событий в JavaScript

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

JavaScript Event Loop

         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

Цикл событий JavaScript

console.log('Hi!');

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

console.log('Bye!');

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

JavaScript Event Loop

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

Ответы похожие на “Что такое цикл событий в JavaScript”

Вопросы похожие на “Что такое цикл событий в JavaScript”

Больше похожих ответов на “Что такое цикл событий в JavaScript” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования