LearnFrenzy
Sign in Take a free test

Functions · Find the Error · Question 3

Error: an arrow function returning an object 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
const makeUser = (name) => { name: name, active: true };
console.log(makeUser("Asha"));
  • A It prints { name: 'Asha', active: true }
  • B It prints undefined
  • C SyntaxError: the braces are read as a function body, not an object – wrap it: (name) => ({ name, active: true }) Correct
  • D TypeError: makeUser is not a function
Correct Answer: Option C

After =>, { starts a block. name: becomes a label and the comma part is invalid. Parentheses turn the braces into an object literal.

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