• 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

June 17th, 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 Is the Life of a Programmer Lonely?

Huzoor Bux

I am a PHP Developer

Related Posts

9 Best Programming languages you should learn in 2021 Tips
June 19th, 2025

9 Best Programming languages you should learn in 2021

What is Progressive Web Applications and Why Create a PWA? Guide
June 19th, 2025

What is Progressive Web Applications and Why Create a PWA?

Introduction to Git for version control Guide
June 18th, 2025

Introduction to Git for version control

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
  • 9 Best Programming languages you should learn in 2021
  • What is Progressive Web Applications and Why Create a PWA?
  • 7 HTML attributes that you must learn today!
  • Why Use MongoDB and When to Use It?
  • Introduction to Git for version control
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
  • How to
  • javascript
  • laravel
  • MYSQL
  • PHP framework
  • css
  • jQuery
  • HTML to PDF
  • Web Development
  • About
  • Privacy Policy
  • Back to top
© PHPLift.net. All rights reserved.
 

Loading Comments...