DEV Community

Joshua Byrd
Joshua Byrd

Posted on • Updated on


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(""); // 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)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.