



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















async keyword do when added to a function? async keyword makes a function return a Promise, allowing the use of await within the function.__________ method is used to execute a function after a specified delay. Answer: setTimeout Rationale: The setTimeout method is used to execute a function after a specified delay.__________ method is used to repeatedly execute a function at specified intervals. Answer: setInterval Rationale: The setInterval method is used to repeatedly execute a function at specified intervals.__________ function is used to create a new Promise. Answer: Promise Rationale: The Promise function is used to create a new Promise.__________ keyword is used to wait for a Promise to resolve. Answer: await Rationale: The await keyword is used to wait for a Promise to resolve in an async function.__________ method is used to handle the final state of a Promise, regardless of its outcome. Answer: finally Rationale: The finally method is used to handle the final state of a Promise, regardless of its outcome.async keyword can only be used with functions that return a Promise.Promise.race() method waits for the first Promise to resolve or reject. Answer: True Rationale: The Promise.race() method waits for the first Promise to resolve or reject.new Promise(resolve, reject)new Promise((resolve, reject) => {})Promise.create((resolve, reject) => {})Promise.new((resolve, reject) => {}) Answer: B Rationale: The correct way to create a new Promise is new Promise((resolve, reject) => {}).Promise.resolve() method do? Promise.resolve() method creates a new Promise that is already resolved.Promise.allSettled() method?Promise.allSettled() method waits for all Promises to settle (resolve or reject).Promise.reject() method?Fill-in-the-Blank: Callback functions are commonly used in JavaScript to handle _ operations. Correct Answer: asynchronous Rationale: Callback functions are frequently used in JavaScript to manage asynchronous operations, ensuring that certain tasks are executed after others have completed. True/False: Asynchronous code in JavaScript always runs in parallel with synchronous code. Correct Answer: False Rationale: Asynchronous code in JavaScript does not always run in parallel with synchronous code; it allows certain tasks to be executed independently of the main program flow. Multiple Choice: Which function is used to handle errors in asynchronous JavaScript code? A) errorHandler() B) catch() C) tryCatch() D) handleError() Correct Answer: B) catch()
Rationale: The catch() method is used to handle errors in asynchronous JavaScript code, allowing developers to manage and respond to exceptions that occur during asynchronous operations. Fill-in-the-Blank: Promises in JavaScript are used to represent the eventual completion (or failure) of an _ operation. Correct Answer: asynchronous Rationale: Promises in JavaScript are a mechanism for handling asynchronous operations, providing a way to work with asynchronous code in a more organized and manageable manner. True/False: The async keyword in JavaScript is used to define a function that executes synchronously. Correct Answer: False Rationale: The async keyword in JavaScript is used to define a function that returns a promise, allowing the function to execute asynchronously. Multiple Choice: Which method is used to run multiple asynchronous operations concurrently in JavaScript? A) parallel() B) all() C) together()
A) resolve B) then C) complete D) finish Correct Answer: B) then Rationale: The then keyword in JavaScript is used to handle promises and specify the actions to take when a promise is resolved. Fill-in-the-Blank: The async/await syntax in JavaScript provides a more _ way of working with promises. Correct Answer: synchronous Rationale: The async/await syntax allows developers to write asynchronous code in a more synchronous and readable manner, simplifying the handling of promises. True/False: JavaScript's event loop is responsible for managing asynchronous operations and callbacks. Correct Answer: True Rationale: The event loop in JavaScript is a key mechanism for managing asynchronous operations, ensuring that callback functions are executed at the appropriate times. Multiple Choice:
Which function is used to reject a promise in JavaScript? A) reject() B) fail() C) error() D) catch() Correct Answer: A) reject() Rationale: The reject() function is used to reject a promise in JavaScript, indicating that the promised task has failed or encountered an error. Fill-in-the-Blank: The Promise.race() method in JavaScript resolves or rejects a set of promises as soon as the _ promise is resolved or rejected. Correct Answer: first Rationale: The Promise.race() method in JavaScript operates on a set of promises and resolves or rejects them based on the first promise that is resolved or rejected. True/False: Asynchronous code in JavaScript can lead to callback hell, making code difficult to read and maintain. Correct Answer: True Rationale: Asynchronous code in JavaScript, if not properly structured, can lead to callback hell - a situation where nested callbacks make code hard to read and maintain.
Rationale: The setTimeout() function in JavaScript is an asynchronous operation that schedules a function to run after a specified amount of time, allowing the code to continue executing without waiting for the delay to finish. Multiple Choice: Which method is used to convert a callback-based function to a promise- based function in JavaScript? A) toPromise() B) promisify() C) callbackToPromise() D) convert() Correct Answer: B) promisify() Rationale: The promisify() method in JavaScript is commonly used to convert callback-based functions into promise-based functions, simplifying the handling of asynchronous operations. Fill-in-the-Blank: JavaScript's async/await syntax is built on top of _ and provides a more intuitive way of working with promises. Correct Answer: promises Rationale: The async/await syntax in JavaScript builds upon promises and offers developers a more intuitive and synchronous way of interacting with asynchronous code, enhancing readability and maintainability.
Correct Answer: True Rationale: Asynchronous code execution helps prevent blocking operations, enhancing the responsiveness of web applications.
Correct Answer: True Rationale: Asynchronous code execution allows the main thread to continue executing other tasks while waiting for asynchronous operations to complete.