W3Tutorials.net
Toggle Menu
Home
Online Go Compiler
Tutorials
Javascript Tutorials
Python Tutorials
Go Tutorials
Blog
All Posts
JavaScript Async Programming
Test your knowledge of promises,async/await,and callbacks.
1. What is the primary purpose of async/await in JavaScript?
Simplify promise syntax
Replace callbacks entirely
Execute code synchronously
Block the event loop
2. What does an async function return by default?
A promise
Undefined
A callback function
The resolved value directly
3. Which of the following are valid promise methods?
then()
catch()
finally()
all()
map()
4. The 'fetch' API returns a promise.
True
False
5. Name the function used to schedule a callback to run after a specified delay (full name).
6. Which promise method waits for all input promises to resolve or any to reject?
Promise.all()
Promise.race()
Promise.allSettled()
Promise.resolve()
7. Which of the following are classified as microtasks in the JavaScript event loop?
Promise callbacks (then/catch/finally)
setTimeout callbacks
queueMicrotask() callbacks
requestAnimationFrame callbacks
8. Using 'await' inside a non-async function will throw a syntax error.
True
False
9. What happens if a promise is rejected and no rejection handler (catch/finally) is provided?
The error is silently ignored
An unhandled rejection error is logged to the console
The JavaScript engine crashes
The promise automatically resolves to null
10. Which of these are valid ways to handle errors in async/await code?
try/catch blocks
.catch() method on the promise
window.onerror event listener
throw statement without a catch
11. The JavaScript event loop is responsible for executing code, collecting and processing events, and handling queued sub-tasks.
True
False
12. What is the name of the promise method that waits for all input promises to settle (either resolve or reject)?
13. Which keyword is used to pause execution until a promise is resolved or rejected?
await
async
then
resolve
14. Which of the following are asynchronous operations in JavaScript?
setTimeout(() => {}, 1000)
fs.readFileSync('file.txt')
fetch('https://api.example.com')
Promise.resolve('value')
15. A promise can exist in one of three states: pending, resolved, and rejected.
True
False
Reset
Answered 0 of 0 — 0 correct