Q
How can you ensure that a callback runs only once, even if the promise is resolved multiple times?

Answer & Solution

Answer: Option D
Solution:
The then() method ensures that a callback runs only once, even if the promise is resolved multiple times, by handling both success and failure cases appropriately.
Related Questions on Average

What is event delegation in jQuery?

A). Attaching event handlers to dynamically created elements

B). Attaching event handlers to static elements

C). Attaching event handlers to parent elements

D). Attaching event handlers to all elements

What is a promise in jQuery?

A). An object that represents a completed task

B). An object that represents a pending task

C). An object that represents an asynchronous operation

D). An object that represents a synchronous operation

What is the purpose of the done() method in jQuery promises?

A). To handle failed operations

B). To handle completed operations

C). To handle pending operations

D). To create a new deferred object

What is a deferred object in jQuery?

A). An object that stores HTML elements

B). An object that represents a task that will finish in the future

C). An object that handles CSS styles

D). An object that manages event listeners

What does the fail() method do in jQuery promises?

A). Attaches a callback for when the promise is rejected

B). Attaches a callback for when the promise is resolved

C). Attaches a callback for when the promise is pending

D). Attaches a callback for when the promise is created

How can event delegation improve performance?

A). By reducing the number of event handlers

B). By increasing the number of event handlers

C). By attaching handlers directly to elements

D). By using inline event handlers

Which method is used to delegate an event handler in jQuery?

A). .on()

B). .delegate()

C). .bind()

D). .attach()

Which jQuery method is used to handle both success and failure cases of a promise?

A). done()

B). fail()

C). always()

D). then()

How can you create a promise from a deferred object in jQuery?

A). Using the promise() method

B). Using the then() method

C). Using the done() method

D). Using the fail() method

What does the promise() method return in jQuery?

A). A new deferred object

B). A new promise object

C). A new callback function

D). A new event handler