async/await explained as simply as I humanly possibly can

twitter logo github logo ・1 min read

Put async in front of a function.

eg. async function test() {} or const test = async () => {}

Now you can use await inside that function to pause and wait for values that take their time getting back to us.

Here's an async function:

// Define our async function and let it use await
async function test() {
  const response = await fetch("https://api.github.com/"); // Wait for the Promise
  const json = await response.json(); // Wait to resolve the Promise
  console.log(json); // Log the response
}

test(); // Run the function

Okay that's it! Get it now?

If not, go here for a better explanation. Or leave a comment and I'll try to help out.

twitter logo DISCUSS
Classic DEV Post from Apr 18

The Weird Rules I Set Myself That Got Me a Job

Joshua Byrd profile image
200 BIO OK

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️