Question 11
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const currency = "USD";
function format(amount) {
return `${amount} ${currency}`;
}
function indianPrice(amount) {
const currency = "INR";
return format(amount);
}
console.log(indianPrice(500));
- A Template literals cannot use outer variables
- B Scope is lexical: format() reads the top-level currency, not the caller's local one – pass the currency as a parameter Correct
- C const currency inside indianPrice is a SyntaxError
- D format() should be an arrow function
Correct Answer: Option B
A function never sees its caller's local variables. function format(amount, currency = "USD") and format(amount, "INR") fixes 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!