Here’s a scenario: imagine you’re the CEO of a wildly successful new company. You have a luxury office at the very top of a high-rise in your city of choice. You are absolutely drowning in money and fame. Unfortunately, you are also drowning in work. Now, you have three things to do before you attend a meeting with your employees in an hour. First, you need to create a spreadsheet for the company’s budget. Second, you need to have your assistant pick up any company mail from the mailbox downstairs. Third, you need to email your new budget to the company’s investors.

So you get to work in Excel, and after forty minutes you’ve got your monthly budget planned out. You call your assistant, and tell them to go down to the first floor and get your mail. And then you wait… and wait… and wait. Twenty minutes later, your assistant comes back, dripping with sweat. The elevators are out of order, and they’ve just had to jog down and up ten flights of stairs. You now have to rush to your meeting, and your stockholders won’t receive the budget until afterwards!

Except, that’s not what a hard-working entrepreneur would have done, is it? Sitting there twiddling your thumbs while your assistant did your errands would be an enormous waste of time. While they were braving the staircase, you could just as easily have emailed out your budget, and had time to spare!

Congratulations, snazzy new business exec! You’ve just uncovered a concept called asynchrony.

Image for post

Sorry; no relation to the Police album

To start to tie this back into JavaScript, let’s try illustrating the previous list of tasks in pseudo-code.

const investors = ["Warren Buffet", "Bill Gates", "Tony Stark", "another famous rich person"]

createBudget();
haveAssistantGetMail();
investors.forEach(investor => {
   emailBudgetTo(investor);
}

#web-development #coding #javascript #flatiron-school #asynchronous

Asynchronicity: An Intro to Asynchrony in JavaScript
1.10 GEEK