CodeNewbie Community

Discussion on: What is the difference between synchronous and asynchronous?

Collapse
ben profile image
Ben Halpern

"Synchronous" means that one thing happens after another. It's probably the simplest way to program. The events of line 11 will always happen after line 10.

"Asynchronous" means that the events of line 11 might begin before the events of line 10 complete. JavaScript is generally synchronous, but allows for asynchronous functionality. Things like fetching the results of a web request are often done asynchronously— And for good reason. If you need to fetch data from a URL, it is not very efficient to wait around doing nothing while the request is sent and returned. Where possible, it's good if other code can execute. For example, I may also want to respond to a separate click event while I wait.

All in all, reconciling async code can be complicated. JavaScript has several ways to accomplish sane async programming. Check out this explanation of promises and async/await for more info.