w3resource

JavaScript Asynchronous: Exercises, Practice, Solutions

JavaScript Asynchronous Programming [ 9 exercises with solution ]

[An editor is available at the bottom of the page to write and execute the scripts.  Go to the editor]

1. Write a JavaScript function that takes a callback and invokes it after a delay of 2 second.

Click me to see the solution

2. Write a JavaScript program that converts a callback-based function to a Promise-based function.

Click me to see the solution

3. Write a JavaScript a function that makes an HTTP GET request and returns a Promise that resolves with the response data.

Click me to see the solution

4. Write a JavaScript function that takes an array of URLs and downloads the contents of each URL in parallel using Promises.

Click me to see the solution

5. Write a JavaScript program that implements a function that performs a series of asynchronous operations in sequence using Promises and 'async/await'.

Click me to see the solution

6. Write a JavaScript function that fetches data from multiple APIs concurrently and returns a combined result using Promises and 'Promise.all()'.

Click me to see the solution

7. Write a JavaScript function that fetches data from an API and retries the request a specified number of times if it fails.

Click me to see the solution

8. Write a JavaScript program to implement a function that executes a given function repeatedly at a fixed interval using 'setInterval()'.

Click me to see the solution

9. Write a JavaScript function that fetches data from an API and cancels the request if it takes longer than a specified time.

Click me to see the solution

More to Come !

* To run the code mouse over on Result panel and click on 'RERUN' button.*

Live Demo:

See the Pen javascript-common-editor by w3resource (@w3resource) on CodePen.


Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/javascript-exercises/asynchronous/