/ synchronous

What do Synchronous and Asynchronous mean?

Yesterday, I was working on a function in a test runner that executes synchronously. My task was to send a message to Slack. It sounds easy enough, I'm sure I could do it myself with a request POST. However, NPM has packages available. I'll just pull one in.

I tried package after package. None of them worked. They never executed the actual POST. After some troubleshooting, it turns out they're all running in asynchronous mode. This promted me to think, "Do I even know what synchronous and asynchronous mean?" I thought I understood and my original function should have worked.

It turns out, I was definitely wrong. I had them backwards. In most areas, I understood enough of what would happen in Javascript, but not the why. This led to my day of frustration at sending a simple POST request.

When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes.
Stack Overflow - Adam Robinson

BUT WHY?!?!?! It seems so counter intuitive. Synchronous should be code executing as the same time and asynchronous should be code executing one line at a time. Not suprisingly, other people were just as confused as I was.

Oddly enough "Synchronously" means "using the same clock" so when two instructions are synchronous they use the same clock and must happen one after the other. "Asynchronous" means "not using the same clock" so the instructions are not concerned with being in step with each other. That's why it looks backwards, the term is not referring to the instructions relationship to each other. It's referring to each instructions relationship to the clock. Hope that helps
Stack Overflow - Tom Padilla

So there you have it, keep in mind that why discussing sync/async in Javascript, its related to the clock by which the program runs and you'll be able to understand what should or should not work.