JavaScript 运行原理解析

关于Js的运行原理,《JavaScript 运行原理解析》这篇文章写的很易懂,而且想要了解更深入,文章的参考链接都值得细读
关键知识点:

事件循环(Event Loop)和事件队列(Callback Queue)和调用栈(Call Stack)之间的关系:
Event Loop只做一件事情,负责监听Call Stack和Callback Queue。当Call Stack里面的调用栈运行完变成空了,Event Loop就把Callback Queue里面的第一条事件(其实就是回调函数)放到调用栈中并执行它,后续不断循环执行这个操作,这就是事件循环。

console.log('Hi');
setTimeout(function cb1() { 
    console.log('cb1');
}, 5000);
console.log('Bye');
JavaScript 运行原理解析_第1张图片
事件循环

参考链接:

  1. How JavaScript works: Event loop and the rise of Async programming + 5 ways to better coding with async/await
  2. How JavaScript works: an overview of the engine, the runtime, and the call stack
  3. Philip Roberts: What the heck is the event loop anyway?
  4. Tasks, microtasks, queues and schedules

你可能感兴趣的:(JavaScript 运行原理解析)