Posts

Understanding the Event Loop, Callbacks JS

Image
  Introduction In the early days of the internet, websites often consisted of static data on an HTML page. But now that web applications have become more interactive and dynamic, it has become increasingly necessary to do intensive operations like make external network requests to retrieve  API  data. To handle these operations in JavaScript, a developer must use  asynchronous programming  techniques. The Event Loop This section will explain how JavaScript handles asynchronous code with the event loop. It will first run through a demonstration of the event loop at work, and will then explain the two elements of the event loop: the stack and the queue. JavaScript code that does not use any asynchronous Web APIs will execute in a synchronous manner—one at a time, sequentially. This is demonstrated by this example code that calls three functions that each print a number to the console: // Define three example functions function first ( ) { console ....