News for hackers. Stuff that matters.
Re:Ask HN: Why can't await be used from non-async functions? by claytongulick on Monday February 28, 2022 @01:11PM (#30502988)
I think this is technically incorrect.

It's perfectly valid to await on a literal:

  > async function test() {

    let a = "yep"; 
    await a; 
    console.log(a); 

  }

  > test()

  > yep
Re:Ask HN: Why can't await be used from non-async functions? by Blahah on Monday February 28, 2022 @01:24PM (#30503143)
when you use `await a`, a is wrapped in a promise. Try returning await a - you get a promise and not the literal. In your example you don't use the promise, and a is a literal.

> async function test() {

  let a = "yep"; 
  return await a; 
}

> let b = test()

> console.log(b)

> Promise { 'yep', [Symbol(async_id_symbol)]: 1215, [Symbol(trigger_async_id_symbol)]: 5, [Symbol(destroyed)]: { destroyed: false } }

The promise you create with `await a` resolves immediately (equivalent to Promise.resolve(a)), but it's still a promise.