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.
2. Callback to Promise Conversion
Write a JavaScript program that converts a callback-based function to a Promise-based function.
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.
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.
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'.
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()'.
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.
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()'.
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.
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics