Asynchronous JavaScript (original) (raw)
What is the purpose of the setTimeout function?
- Executes a function repeatedly at fixed intervals
- Executes a function once after a delay
- Executes a function immediately
- Cancels a delayed function
What does the then() method of a Promise do?
- Handles rejected promises
- Cancels an unresolved promise
- Converts a callback to a promise
- Handles fulfilled promises
Which method allows handling errors in promises?
What does async do when used with a function?
- Makes the function synchronous
- Automatically wraps the function's return value in a promise
- Stops the execution of the function
- Immediately executes the function
What is the purpose of the await keyword?
- Delays code execution indefinitely
- Converts a promise into a callback
- Pauses execution of an async function until a promise resolves
- Handles rejected promises
What is the difference between setTimeout and setInterval?
- setTimeout runs once, while setInterval executes repeatedly at intervals
- setTimeout executes repeatedly, while setInterval runs once
- Both execute functions immediately
- Both are used for canceling asynchronous tasks
What is the event loop's role in JavaScript?
- To execute synchronous code
- To prioritize promises over callbacks
- To manage and execute asynchronous operations in the call stack
Which queue has a higher priority in the JavaScript event loop?
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");
`
What is the purpose of Promise.finally()?
- Executes only when a promise is fulfilled
- Executes only when a promise is rejected
- Cancels unresolved promises
- Executes after a promise is settled, regardless of its state
There are 10 questions to complete.
Take a part in the ongoing discussion