Q: Does the keyword "await" from Async Await in JavaScript only work for promise? When await is written inside an async function Like -
let x = await doSomething()

Does the doSomething function has to return a Promise?

A: It may return anything because
let x = await doSomething()
// ... rest of your code

// is roughly equivalent

Promise
  .resolve(doSomething())
  .then(value => {
    let x = value

    // ... rest of your code
  })

But if doSomething is async it has to return something "thenable" so that await could actually work


const doSomething = () => ({
  then(fn) {
    setTimeout(fn, 2000, 'hello')
  }
})

const run = async () => {
  let msg = await doSomething()
  
  console.log(msg)
}

run().then(() => console.log('Done'))


