const wait = new Promise((resolve) => setTimeout(resolve, ms))
      const asyncFunction = async() => {
          await wait(1000)
          console.log('async')
      }
      asyncFunction()

      Javascript language logo
      Await function

      await
      function
      async
      Javascript recipes

      When the code is executed, the console will print "async" before the code inside the asyncFunction is executed. This is because the code inside the asyncFunction is being executed asynchronously, meaning that it isn't wait()ing for the result of the Promise that resolves in 1000 ms.

      Shortcut: await

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.