JSFiddle - React, Tailwind, and code Playground

by محمد رستمیانی

JavaScript

async function waitAndreturn() {
  // Wait one second
  await new Promise((r) => setTimeout(r, 1000));

  return "the string";
}

function direct() {
  return waitAndreturn();
}

async function empty() {
  await waitAndreturn();
  return;
}

async function run() {
  console.log("Returning promise: ", await direct());
  console.log("Empty return: ", await empty());
}

run();

// Output:

// Returning promise:  the string
// Empty return:  undefined