LearnFrenzy
Sign in Take a free test

Closures · Find the Error · Question 3

Error: an expression inside an object literal Answer, explanation & discussion

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

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

main.js
function makeTicker() {
  let count = 0;
  return { count++ };
}
  • A SyntaxError: { count++ } is an object literal and needs key: value pairs – return a function such as { tick: () => count++ } Correct
  • B It returns 0
  • C It returns { count: 1 }
  • D TypeError
Correct Answer: Option A

After return, { starts an object literal; count++ is not a property definition. Expose behaviour through methods.

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