Synchronous code is executed sequentially from the top of a file to the end of a file — with each line unable to execute until the previous line has finished executing.
Asynchronous code can be executed in parallel to other code that is already running.
Blocking occurs when code prevents a user from interacting with an app due to background code not finishing execution.
Generally, the amount of tasks a language can execute is limited by the amount of threads the language has access to.
JavaScript is a single-threaded language. However, it can handle asynchronous code using the event loop.
In JavaScript, asynchronous code can be written in a variety of different ways, including:
async
/await
setTimeout()
accepts two arguments:
setInterval()
accepts two arguments: