Asynchronous JavaScript

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the setTimeout function?

  • A

    Executes a function repeatedly at fixed intervals

  • B

    Executes a function once after a delay

  • C

    Executes a function immediately

  • D

    Cancels a delayed function

Question 2

What does the then() method of a Promise do?

  • A

    Handles rejected promises

  • B

    Cancels an unresolved promise

  • C

    Converts a callback to a promise

  • D

    Handles fulfilled promises

Question 3

Which method allows handling errors in promises?

  • A

    catch()

  • B

    then()

  • C

    resolve()

  • D

    finally()

Question 4

What does async do when used with a function?

  • A

    Makes the function synchronous

  • B

    Automatically wraps the function's return value in a promise

  • C

    Stops the execution of the function

  • D

    Immediately executes the function

Question 5

What is the purpose of the await keyword?

  • A

    Delays code execution indefinitely

  • B

    Converts a promise into a callback

  • C

    Pauses execution of an async function until a promise resolves

  • D

    Handles rejected promises

Question 6

What is the difference between setTimeout and setInterval?

  • A

    setTimeout runs once, while setInterval executes repeatedly at intervals

  • B

    setTimeout executes repeatedly, while setInterval runs once

  • C

    Both execute functions immediately

  • D

    Both are used for canceling asynchronous tasks

Question 7

What is the event loop's role in JavaScript?

  • A

    To execute synchronous code

  • B

    To prioritize promises over callbacks

  • C

    To manage and execute asynchronous operations in the call stack

  • D

    To handle HTTP requests

Question 8

Which queue has a higher priority in the JavaScript event loop?

  • A

    Callback queue

  • B

    Timer queue

  • C

    Render queue

  • D

    Microtask queue

Question 9

What is the output of the following code?

JavaScript
console.log("A");
setTimeout(() => 
	console.log("B"), 0);
Promise.resolve().then(() => 
	console.log("C"));
console.log("D");


  • A

    A, B, C, D

  • B

    A, D, B, C

  • C

    A, D, C, B

  • D

    B, C, A, D

Question 10

What is the purpose of Promise.finally()?

  • A

    Executes only when a promise is fulfilled

  • B

    Executes only when a promise is rejected

  • C

    Cancels unresolved promises

  • D

    Executes after a promise is settled, regardless of its state

There are 10 questions to complete.

Take a part in the ongoing discussion