Question 9
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const order = null; // order not found
switch (order.status) {
case "shipped": console.log("On the way"); break;
default: console.log("Processing");
}
- A It prints Processing
- B TypeError: order is null, so order.status cannot be read before the switch even starts Correct
- C It prints On the way
- D Nothing is printed
Correct Answer: Option B
The switch expression is evaluated first and throws. Guard it: if (!order) return …; or switch (order?.status).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!