“Synchronous basically means that you can only execute one thing at a time. Asynchronous means that you can execute multiple things at a time and you don’t have to finish executing the current thing in order to move on to next one.”
“The Internet”, “The Web”, “Web Apps”. All of these terms describe something that is interconnected. If you zoom out a bit, the entire internet is basically billions of computers all sharing information and software! But so far your projects have been all alone on your computer :(
Everything you have learned so far happens on the callstack, everything on the callstack executes synchronously. Synchronous means that each line of code will finish executing before the next one starts. Think of infinite loops, your browser freezes because nothing else can happen while the loop is looping!
What makes web development so cool is the … web. Being able to build applications that connect computers form across the internet. This also introduces some challenges, it can take some time for computers to talk to each other across the internet. You don’t want your apps freezing while you wait to hear back from another computer.
Enter asynchronous programming: writing code that tells your browser to start one task and move on to a new task while you wait for the first to finish. This is possible because of the Event Loop.
setTimeout
and setInterval
to schedule simple tasks.fetch
data from RESTful APIs..then
Promise.all
system./api-calls
, /handlers
and async
/await
syntax.async
/await
syntax.You can also run tests directly from CLI using the NPM script:
npm run test -- ./path/to/file.js