ArtOfCode.org
Toggle Menu
Home
Online Rust Compiler
Tutorials
Algorithms 101
Html Css Tutorial
Javascript Tutorial
Blog
All Posts
Asynchronous JavaScript
Use callbacks promises and async await.
1. What is the primary purpose of using async/await in JavaScript?
To write synchronous code
To simplify asynchronous code
To increase execution speed
To handle errors in synchronous functions
2. Which of the following are examples of microtasks in JavaScript?
Promise.then()
setTimeout()
fetch().then()
queueMicrotask()
setInterval()
3. The event loop is responsible for executing code, collecting and processing events, and handling subtasks in JavaScript.
True
False
4. What does the acronym 'API' stand for in the context of asynchronous operations?
5. Which method is used to attach a callback function that executes when a promise is rejected?
.then()
.catch()
.finally()
.resolve()
6. Which of the following operations are typically asynchronous in JavaScript?
Reading a file from the local filesystem
console.log('Hello')
Fetching data from a remote server using fetch()
setTimeout(() => {}, 1000)
Calculating the sum of two numbers
7. A JavaScript promise can transition from the 'rejected' state back to the 'pending' state.
True
False
8. What keyword is used to declare an asynchronous function that implicitly returns a promise?
9. What will the following code log to the console? console.log('Start'); setTimeout(() => { console.log('Timeout'); }, 0); Promise.resolve().then(() => { console.log('Promise'); }); console.log('End');
Start, End, Timeout, Promise
Start, Promise, End, Timeout
Start, End, Promise, Timeout
Start, Timeout, End, Promise
10. Which of the following statements about JavaScript promises are true?
A promise can be resolved or rejected only once
A promise can transition from 'rejected' to 'fulfilled' state
Promise.all() rejects immediately if any of the input promises reject
Promise.race() returns the first promise that settles (either resolves or rejects)
Promises were introduced in ECMAScript 5
Reset
Answered 0 of 0 — 0 correct