Asynchronous JavaScript Fundamentals Quiz Quiz

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.

  1. Identifying Asynchronous Code

    Which of the following methods executes a function asynchronously after a specified delay?

    1. setTimeout
    2. join
    3. splitTime
    4. parseInt
    5. addEventListener
  2. Basic Callback Understanding

    In JavaScript, what is the term for a function that is passed as an argument to another function and executed later?

    1. Handler
    2. Closure
    3. Prompt
    4. Return function
    5. Callback
  3. Promise States

    When you create a new Promise, which of the following is NOT a possible state of the promise?

    1. Settled
    2. Pending
    3. Rejected
    4. Fulfilled
    5. Completed
  4. Promise Usage

    Which method would you use to handle a successful resolution of a promise?

    1. resolve
    2. fail
    3. awaited
    4. async
    5. then
  5. Async Function Keyword

    To define an asynchronous function that uses 'await', what keyword must you place before the function declaration?

    1. promise
    2. await
    3. asynchron
    4. defer
    5. async
  6. Understanding the Event Loop

    What does the JavaScript event loop do?

    1. Processes event queue and microtasks after the current code finishes
    2. Manages browser cookies
    3. Defines function scope
    4. Executes variable hoisting
    5. Parses HTML files
  7. setInterval Usage

    Which function repeatedly executes a callback at fixed time intervals?

    1. setTimeoutLoop
    2. setOnce
    3. setRepeat
    4. setInterval
    5. intervalRepeat
  8. Arrow Functions as Callbacks

    Which syntax can be used to pass an arrow function as a callback to an array's map method?

    1. array.map(item u003C=u003E item * 2)
    2. array.map(*item =u003E item * 2)
    3. array.mapping(item : item * 2)
    4. array.map(item, function =u003E item * 2)
    5. array.map(item =u003E item * 2)
  9. Promise.all Result

    What does Promise.all([promise1, promise2]) return when all promises are fulfilled?

    1. The first resolved value only
    2. A Boolean value
    3. Null
    4. A new promise that resolves to an array of results
    5. A single combined string
  10. Handling Promise Errors

    Which method can be used to handle errors in a promise chain?

    1. abort
    2. return
    3. else
    4. getError
    5. catch
  11. Microtasks vs Macrotasks

    In the event loop model, which is checked and executed first after the current stack clears?

    1. Timers
    2. Microtasks
    3. Callbacks
    4. HTML parsing
    5. Macrotasks
  12. Using await with Promises

    What does the 'await' keyword do when placed before a promise inside an async function?

    1. Ignores the promise and returns instantly
    2. Pauses function execution until the promise resolves
    3. Returns a rejected promise
    4. Executes code outside the function
    5. Throws a syntax error
  13. Callback Hell Recognition

    What is the term for deeply nested callbacks leading to hard-to-read code?

    1. Async confusion
    2. Loop lock
    3. Function callback
    4. Promise cycle
    5. Callback hell
  14. Promise.resolve Purpose

    What does Promise.resolve(5) return?

    1. A promise fulfilled with value 5
    2. A function reference
    3. An asynchronous error
    4. A new callback function
    5. The value 5 directly
  15. Chaining with Promises

    What does returning a value from a promise 'then' handler do?

    1. Rejects the promise
    2. Passes the value to the next 'then' handler
    3. Causes an infinite loop
    4. Throws a syntax error
    5. Stops the promise chain