DEV Community

Joshua Byrd
Joshua Byrd

Posted on • Edited on

9 3

async/await explained as simply as I humanly possibly can

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay