Posts How dose JavaScript work?
Post
Cancel

How dose JavaScript work?

JavaScript

  • Single-threaded
  • Non-blocking
  • Asynchronous
  • Concurrent

V8 Engine

image

  • Heap
    • where memory allocation happes.
  • Stack
    • To save the JS function programming.
    • On each new function call, it’s pushed on top of the stack
  • Web APIS
    • Extra thhings are the browser provides. DOM, AJAX, timeout etc
  • Callback Queue
    • When a process finished its job, such as a xhr call, it’s dropped in a callback queue.
    • Callback queue is triggered by event loop process after our stack is empty which means the process waits in that queue until our stack is empty.
    • Once our stack has no function call, then a process is popped-out from callback queue and pushed in to stack
  • Event loop
    • A process which is responsible to check our stack and then trigger our callback queue continuously.

The call stack

  • one thread == one call stack == one thing at a time

Visualizing JS runtime

Reference

This post is licensed under CC BY 4.0 by the author.