LearnFrenzy
Sign in Take a free test

JavaScript Basics · Find the Error · Question 12

Error: assignment to a const Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
const pi = 3.14;
console.log("Area:", pi * 2 * 2);
pi = 3.14159;
console.log("Area:", pi * 2 * 2);
  • A SyntaxError before anything is printed
  • B It prints both areas
  • C It prints the first area, then TypeError: Assignment to constant variable Correct
  • D ReferenceError: pi is not defined
Correct Answer: Option C

Reassigning a const is a run-time TypeError, so the first line runs and prints Area: 12.56. Use let if the value must change.

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