JavaScript Promises & Promise Chaining Quiz

JavaScript
0 Passed
0% acceptance

Tackle 40 questions about JavaScript Promises: states, creating promises, then/catch/finally, value chaining, error propagation, avoiding callback hell, Promise.all, Promise.race, and coordinating multiple async operations.

40 Questions
~80 minutes
1

Question 1

What is a Promise in JavaScript?

A
An object representing the eventual completion or failure of an asynchronous operation
B
A synchronous loop
C
A DOM event
D
A data structure for caching
2

Question 2

Which are the three fundamental Promise states?

A
pending, fulfilled, rejected
B
start, middle, end
C
begin, wait, exit
D
open, closed, paused
3

Question 3

What happens after a Promise settles?

A
Its state becomes immutable
B
It can revert to pending
C
It alternates between fulfilled and rejected
D
It blocks the call stack
4

Question 4

Why were Promises introduced?

A
To provide a structured alternative to callback-heavy asynchronous code
B
To replace loops
C
To speed up synchronous operations
D
To modify CSS rules
5

Question 5

Which two methods register fulfillment and rejection handlers?

A
then and catch
B
map and filter
C
push and pop
D
load and unload
6

Question 6

What does finally do in Promise chains?

A
Runs a callback regardless of fulfillment or rejection
B
Replaces catch
C
Changes the settled state
D
Receives the resolved value
7

Question 7

How does Promise chaining help avoid callback hell?

A
Handlers are attached sequentially with then/catch, keeping code flat
B
Promises eliminate asynchronous operations
C
Promises run synchronously
D
Chaining is equivalent to nested callbacks
8

Question 8

What is a benefit of returning values from a then handler?

A
The returned value becomes the fulfillment value for the next promise in the chain
B
It stops the chain permanently
C
It converts the promise to synchronous
D
It logs values automatically
9

Question 9

Why is error propagation simpler with Promises?

A
Rejections bubble through chain until caught by catch
B
Promises ignore errors
C
Errors must be handled at the start
D
Errors only occur synchronously
10

Question 10

What does Promise.resolve(value) return?

A
A fulfilled promise with the provided value
B
A rejected promise
C
A pending promise that never settles
D
A synchronous value
11

Question 11

What does this promise log?

javascript
const p = new Promise(resolve => {
  resolve('done')
})
p.then(value => console.log(value))
A
done
B
undefined
C
Promise
D
Nothing
12

Question 12

What is printed?

javascript
new Promise((resolve, reject) => {
  reject(new Error('fail'))
})
  .then(() => console.log('won'))
  .catch(err => console.log(err.message))
A
fail
B
won
C
Nothing
D
Error object
13

Question 13

How many times is finally invoked?

javascript
Promise.resolve('ok')
  .finally(() => console.log('cleanup'))
  .then(value => console.log(value))
A
Once, before the subsequent then handler runs
B
Never
C
Twice
D
Only if the promise rejects
14

Question 14

What does the chain output?

javascript
Promise.resolve(2)
  .then(x => x * 3)
  .then(x => Promise.resolve(x + 1))
  .then(result => console.log(result))
A
7
B
6
C
5
D
2
15

Question 15

What happens to the returned promise?

javascript
const p = Promise.resolve('A')
const q = p.then(v => v + 'B')
console.log(p === q)
A
false, because then always returns a new promise
B
true, they are identical
C
Logs undefined
D
Throws an error
16

Question 16

What output occurs?

javascript
Promise.reject('bad')
  .catch(reason => {
    console.log('caught', reason)
    return 'recovered'
  })
  .then(value => console.log(value))
A
caught bad recovered
B
caught bad only
C
recovered only
D
Throws unhandled rejection
17

Question 17

What does this demonstrate?

javascript
Promise.resolve()
  .then(() => Promise.reject('fail'))
  .then(() => console.log('never'))
  .catch(err => console.log('caught', err))
A
Errors thrown or returned as rejections skip subsequent thens until caught
B
catch never runs
C
then always executes
D
Promises ignore rejections
18

Question 18

Which value reaches console.log?

javascript
Promise.resolve('start')
  .then(val => {
    console.log(val)
    return 'next'
  })
  .then(console.log)
A
start next
B
next start
C
start only
D
next only
19

Question 19

What is logged?

javascript
const slow = () => new Promise(resolve => setTimeout(() => resolve('S'), 20))
slow()
  .then(value => value + '1')
  .finally(() => console.log('clean'))
  .then(value => console.log(value))
A
clean S1
B
S1 clean
C
clean only
D
S only
20

Question 20

What does returning a Promise inside then achieve?

A
The next then waits for that promise to settle before receiving the value
B
It converts the chain to synchronous
C
It cancels the chain
D
It forces rejection
21

Question 21

What is Promise chaining?

A
Linking multiple then/catch calls so each step processes the previous result
B
Running promises in parallel
C
Mutating the same promise
D
Using only catch handlers
22

Question 22

How do you propagate synchronous errors in a then handler?

A
Throw inside the handler; the chain converts it to a rejection
B
Return undefined
C
Call console.error
D
Set a global flag
23

Question 23

What happens if you omit catch in a chain?

A
Unhandled rejections occur if any step rejects
B
Errors are silently ignored
C
Promises convert to callbacks
D
The chain stops building
24

Question 24

Why is returning inside then important?

A
Returning ensures the next handler receives the intended value or promise
B
It stops the chain
C
then requires return statements
D
It forces catch to run
25

Question 25

What is an anti-pattern when mixing Promises and callbacks?

A
Creating a new Promise that never resolves/rejects because callbacks are not invoked
B
Returning a Promise from then
C
Using catch for errors
D
Using finally for cleanup
26

Question 26

How does chaining simplify sequential asynchronous work?

A
Each then waits for the prior promise to settle before running
B
All thens run simultaneously
C
Chaining eliminates asynchronous behavior
D
Chaining only works with synchronous code
27

Question 27

Why is catch typically placed near the end of a chain?

A
To handle errors from any previous step in one place
B
Because catch blocks fulfillment
C
Because catch must be first
D
Because catch returns synchronous values only
28

Question 28

What is a microtask queue in relation to Promises?

A
It stores then/catch callbacks that run before the next macrotask
B
It stores DOM events
C
It stores setInterval callbacks
D
It is unrelated to Promises
29

Question 29

What does returning Promise.reject() inside then do?

A
It triggers the next catch with the provided reason
B
It fulfills the chain
C
It stops the script
D
It converts to synchronous errors
30

Question 30

How does Promise chaining compare to nested callbacks for readability?

A
Chaining keeps asynchronous logic linear, reducing indentation and complexity
B
Chaining increases nesting depth
C
Chaining mixes sync and async unpredictably
D
Chaining requires more boilerplate
31

Question 31

What does Promise.all do?

A
Waits for all input promises to fulfill and resolves with an array of their values
B
Resolves after the fastest promise
C
Ignores rejections
D
Runs promises sequentially
32

Question 32

When does Promise.all reject?

A
As soon as any input promise rejects
B
Only after all promises finish
C
Never
D
Only when all rejects
33

Question 33

What does Promise.race return?

A
The result of the first promise to settle (fulfilled or rejected)
B
An array of all results
C
Only rejections
D
Only fulfillments
34

Question 34

How can Promise.all be used efficiently?

A
Kick off multiple independent async operations concurrently and await their combined results
B
Execute tasks sequentially
C
Ignore rejection handling
D
Throttle requests automatically
35

Question 35

What is logged?

javascript
const p1 = new Promise(resolve => setTimeout(() => resolve('A'), 30))
const p2 = Promise.resolve('B')
Promise.all([p1, p2]).then(values => console.log(values.join('-')))
A
A-B
B
B-A
C
A
D
B
36

Question 36

What happens here?

javascript
Promise.race([
  new Promise(resolve => setTimeout(() => resolve('slow'), 50)),
  Promise.resolve('fast')
]).then(console.log)
A
fast
B
slow
C
slow fast
D
Nothing
37

Question 37

How does Promise.all handle rejection reasons?

A
It rejects with the first rejection reason encountered
B
It collects all rejection reasons
C
It ignores rejection reasons
D
It transforms rejections into fulfillments
38

Question 38

Why is Promise.allSettled useful?

A
It waits for all promises to settle and reports each status without short-circuiting
B
It returns the fastest promise only
C
It rejects immediately on error
D
It forces sequential execution
39

Question 39

How do Promises handle multiple async operations efficiently?

A
By starting operations in parallel and using combinators (all, race) to coordinate results
B
By forcing sequential execution only
C
By blocking the event loop
D
By requiring callbacks
40

Question 40

What should you consider when replacing callbacks with Promises?

A
Ensure the original callback follows an error-first pattern so you can map success and failure to resolve/reject
B
Promises eliminate error handling
C
Promises require synchronous I/O
D
Callbacks cannot coexist with Promises

QUIZZES IN JavaScript