Event Loop

Event Loop: you have one job

Monitor the stack & queue

 

If stack is empty, get the next item from the

queue and put it in the stack

 

Javascript Engine

                   * Single-threaded

  • Heap
  • Call stack
  • Callback Queue

               

               Engines implement & optimize differently

Heap

  • Memory allocation
    • variables, functions, instantiations
  • *Garbage collection

Call Stack

  • running functions are added
  • first-in last-out
  • maximum stack size
  • empty stack, next item in queue

Callback Queue

  • future functions to execute
  • * Garbage collection

Garbage Collection

  • account for objects in heap + queue
  • null pointers, throw in garbage
  • Memory Leaks

Resources

  • http://latentflip.com/loupe
  • https://blog.sessionstack.com/how-javascript-works-event-loop-and-the-rise-of-async-programming-5-ways-to-better-coding-with-2f077c4438b5
Made with Slides.com