Question 9
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const amount = 1500;
if (amount > 1000) {
const discount = 10;
}
console.log("Discount:", discount);
- A ReferenceError: discount exists only inside the if block – declare it before the if with let Correct
- B It prints Discount: 10
- C It prints Discount: undefined
- D TypeError: discount is constant
Correct Answer: Option A
const is block-scoped. Declare let discount = 0; before the if and assign inside it.
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!