Test your understanding of how JavaScript handles asynchronous operations, including callbacks, promises, async/await, and the event loop. This quiz covers key concepts related to writing and managing asynchronous code.
Identifying Asynchronous Code
Which of the following methods executes a function asynchronously after a specified delay?
- setTimeout
- join
- splitTime
- parseInt
- addEventListener
Basic Callback Understanding
In JavaScript, what is the term for a function that is passed as an argument to another function and executed later?
- Handler
- Closure
- Prompt
- Return function
- Callback
Promise States
When you create a new Promise, which of the following is NOT a possible state of the promise?
- Settled
- Pending
- Rejected
- Fulfilled
- Completed
Promise Usage
Which method would you use to handle a successful resolution of a promise?
- resolve
- fail
- awaited
- async
- then
Async Function Keyword
To define an asynchronous function that uses 'await', what keyword must you place before the function declaration?
- promise
- await
- asynchron
- defer
- async
Understanding the Event Loop
What does the JavaScript event loop do?
- Processes event queue and microtasks after the current code finishes
- Manages browser cookies
- Defines function scope
- Executes variable hoisting
- Parses HTML files
setInterval Usage
Which function repeatedly executes a callback at fixed time intervals?
- setTimeoutLoop
- setOnce
- setRepeat
- setInterval
- intervalRepeat
Arrow Functions as Callbacks
Which syntax can be used to pass an arrow function as a callback to an array's map method?
- array.map(item u003C=u003E item * 2)
- array.map(*item =u003E item * 2)
- array.mapping(item : item * 2)
- array.map(item, function =u003E item * 2)
- array.map(item =u003E item * 2)
Promise.all Result
What does Promise.all([promise1, promise2]) return when all promises are fulfilled?
- The first resolved value only
- A Boolean value
- Null
- A new promise that resolves to an array of results
- A single combined string
Handling Promise Errors
Which method can be used to handle errors in a promise chain?
- abort
- return
- else
- getError
- catch
Microtasks vs Macrotasks
In the event loop model, which is checked and executed first after the current stack clears?
- Timers
- Microtasks
- Callbacks
- HTML parsing
- Macrotasks
Using await with Promises
What does the 'await' keyword do when placed before a promise inside an async function?
- Ignores the promise and returns instantly
- Pauses function execution until the promise resolves
- Returns a rejected promise
- Executes code outside the function
- Throws a syntax error
Callback Hell Recognition
What is the term for deeply nested callbacks leading to hard-to-read code?
- Async confusion
- Loop lock
- Function callback
- Promise cycle
- Callback hell
Promise.resolve Purpose
What does Promise.resolve(5) return?
- A promise fulfilled with value 5
- A function reference
- An asynchronous error
- A new callback function
- The value 5 directly
Chaining with Promises
What does returning a value from a promise 'then' handler do?
- Rejects the promise
- Passes the value to the next 'then' handler
- Causes an infinite loop
- Throws a syntax error
- Stops the promise chain