Question 3
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
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!