0
0
Javascriptprogramming~5 mins

Promise chaining in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is promise chaining in JavaScript?
Promise chaining is a way to run multiple asynchronous tasks one after another, where each task starts when the previous one finishes, using .then() methods.
Click to reveal answer
beginner
How do you return a value from one promise to the next in a chain?
You return the value inside the .then() callback. This value becomes the input for the next .then() in the chain.
Click to reveal answer
intermediate
What happens if you return a new promise inside a .then() callback?
The next .then() waits for that new promise to resolve before running, allowing you to chain asynchronous operations smoothly.
Click to reveal answer
beginner
How do you handle errors in a promise chain?
You can add a .catch() at the end of the chain to catch any error from any promise in the chain.
Click to reveal answer
beginner
What is the benefit of promise chaining over nested callbacks?
Promise chaining avoids deeply nested code (callback hell), making asynchronous code easier to read and maintain.
Click to reveal answer
What does promise.then() return?
AUndefined
BThe resolved value immediately
CThe original promise
DA new promise
How can you pass data from one promise to the next in a chain?
ABy using global variables
BBy returning the data inside <code>.then()</code>
CBy calling <code>resolve()</code> manually
DBy using <code>setTimeout()</code>
What happens if a promise in the chain rejects and there is no .catch()?
AThe chain stops and error is unhandled
BThe error is ignored
CThe next <code>.then()</code> runs anyway
DThe promise resolves with undefined
Which of these is a correct way to chain promises?
Apromise.then(() => promise2).then(() => promise3)
Bpromise.then(promise2).then(promise3)
Cpromise.then(() => promise2.then(() => promise3))
Dpromise.then(() => promise2).then(promise3())
Why is promise chaining preferred over nested callbacks?
AIt uses less memory
BIt runs faster
CIt makes code shorter and easier to read
DIt avoids using functions
Explain how promise chaining works and why it is useful.
Think about how you can do one task after another without nesting functions.
You got /5 concepts.
    Describe how errors are handled in a promise chain.
    Consider what happens if something goes wrong in any step.
    You got /4 concepts.