# Synchronous vs Asynchronous

# Core JavaScript VS. the Web APIs

The JavaScript that we use in the browser is actually made up of two different things.

There is the Core JavaScript that we were using with Node.JS for the first few weeks of the semester and there are the Web APIs.

The Core part is made up of the features like variables, if statements, functions, data types, arrays, loops, ternary operators, the Math object.

The Web APIs are all the things that are added on top for the browser - HTML DOM, CSS style manipulation, handling AJAX requests, timers (setTImeout and setInterval), the browser events, geolocation, local storage, and all the features added to support mobile devices.

# The JavaScript Loop

The JavaScript engines, like Chrome's V8, use a single thread to process all your code. It builds a stack of commands to run, in the order that you have written them. As long as each command belongs to the CORE JavaScript then it gets added to the main run stack.

When something that belongs to the Web APIs is encountered it gets added to a secondary list of tasks. Each time the main stack is finished then the JavaScript engine turns it attention to the secondary list of tasks and will try to run those.

The video below does a great job explaining all the parts of this process. It is about 25 minutes so give yourself some time to watch it.

You don't need this information to do any of the assignments this semester. However, it will help you to avoid errors in your code and to better understand how your code will be interpreted by the JavaScript engine. This will lead to you writing much better code in the long run.

# Learn about Synchronous vs Asynchronous

This is a quicker video with practical examples of the differences between synchronous and asynchronous JavaScript commands.

Back to Week 9 main page

Last Updated: 6/13/2020, 11:30:19 PM