LearnFrenzy
Sign in Take a free test

Objects · Find the Error · Question 4

Error: a setter without a parameter Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
const thermostat = {
  _celsius: 22,
  set celsius() {
    this._celsius = 25;
  },
};
thermostat.celsius = 30;
  • A It sets _celsius to 30
  • B SyntaxError: a setter must have exactly one parameter, which receives the assigned value Correct
  • C It sets _celsius to 25
  • D TypeError
Correct Answer: Option B

set celsius(value) { this._celsius = value; } – the assigned value is passed as the single argument.

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