LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Predict the Output · Question 19

A closure and a variable changed later Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
let rate = 5;
const interest = (p) => (p * rate) / 100;
rate = 8;
console.log(interest(1000));
  • A 80 Correct
  • B 50
  • C 130
  • D NaN
Correct Answer: Option A

A closure keeps a live link to the variable, not a copy of its value. When interest runs, rate is already 8.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links