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. Delayed Callback Execution

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

Click me to see the solution

2. Callback to Promise Conversion

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

Click me to see the solution

3. HTTP GET with Promises

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. Parallel URL Downloads with Promises

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. Sequential Async Operations

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. Concurrent API Fetch with Promise.all

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. API Fetch with Retry Mechanism

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. Repeated Execution with setInterval

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. API Fetch with Timeout Cancellation

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://www.w3resource.com/javascript-exercises/asynchronous/index.php