• Home
  • PHP
  • MySQL
  • Laravel
  • Demos
  • HTML
  • jQuery
  • Framework
  • Request Tutorial
PHP Lift
  • Home
  • Demos
  • Advertisement
PHP Lift
  • Home
  • PHP
  • MySQL
  • Laravel
  • Demos
  • HTML
  • jQuery
  • Framework
  • Request Tutorial
  • Follow
    • Facebook
    • Twitter
    • Google+
    • Pinterest
    • Youtube
    • Instagram
    • RSS
Understanding async-await in JavaScript
Home
JavaScript

Understanding async-await in JavaScript

August 4th, 2025 Huzoor Bux JavaScript, Tips 0 comments

Facebook Twitter Google+ LinkedIn Pinterest

JavaScript enabled Asynchronous programming to be easier to implement and understand. As a result, special Async and Await were introduced as keywords.

Let’s look at the reasons why they are employed.

Can utilize functions in various scenarios in which the execution of a function is contingent on the results of the previous function and needs to wait for it to be completed.

An easy illustration of this could be one of the most common examples is an API call. The information in the API call needs to be downloaded before performing other operations with it.

Async

An Async function is defined by including the Async keyword in the function. The function returns promises

It could be declared like this

const check = async () => {

      console.log("Async method")

}

Await

Await function is declared the same manner in the same way as the Async method by adding a keyword Await before the declaration of the function.

const check = await () => {

    console.log("Async method")

}

The word “await” must be declared in the Async function.

The wait keyword causes code execution to stop at the line where it is declared until the promise is completed. It does, however, stop it; the process of executing the code will continue on the line where it is declared. It doesn’t stop the execution of the code outside of the Async block.

Now that we can individually compose these tasks, let’s look at what we can accomplish using these functions.

const testMethod = async () => {

    const ret = await "JavaScript!"

    console.log(ret);

}



console.log("Before testMethod() call")

testMethod()

console.log("After testMethod() call")

Output

await async output

 

 

 

 

 

 

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

Related

  • Tags
  • async-await
Facebook Twitter Google+ LinkedIn Pinterest
Next article Convert HTML to PDF in Javascript using jsPDF with Example Download
Previous article How to Migrate from Bootstrap 4 to Bootstrap 5

Huzoor Bux

I am a PHP Developer

Related Posts

Cool New JavaScript Features JavaScript
August 5th, 2025

Cool New JavaScript Features

Drag and drop multiple file upload using jQuery, Ajax, and PHP JavaScript
August 4th, 2025

Drag and drop multiple file upload using jQuery, Ajax, and PHP

Is the Life of a Programmer Lonely? Tips
August 4th, 2025

Is the Life of a Programmer Lonely?

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe
Get new posts by email:
Powered by follow.it
Advertisement
Like us
Recent Posts
  • Laboratory Management System (LIMS) in PHP MySQL – A Complete Guide
  • Cool New JavaScript Features
  • WhatsApp chatbot in Python using Dialogflow.com
  • Cool CSS3 features
  • PHP Contact Form with Google reCAPTCHA V3 Example
Categories
  • API
  • Bootstrap
  • Bot
  • CSS
  • CSS 3
  • Database
  • Designing
  • Framework
  • Guide
  • HTML
  • HTML 5
  • JavaScript
  • jQuery
  • Laravel
  • MySQL
  • Node.js
  • oAuth
  • Payment
  • PHP
  • Python
  • Social
  • Tips
  • Web 3.0
  • WordPress
Weekly Tags
  • PHP
  • javascript
  • How to
  • laravel
  • css
  • HTML to PDF
  • jQuery
  • api
  • Web Development
  • MYSQL
  • About
  • Privacy Policy
  • Back to top
© PHPLift.net. All rights reserved.
 

Loading Comments...