Question 15
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
function makeUser(name) {
return
{
name: name
};
}
console.log(makeUser("Asha"));
- A Object keys must be in quotes
- B The parameter name hides the property name
- C makeUser must be called with new
- D ASI ends the statement after return, so the function returns undefined; put { on the same line as return Correct
Correct Answer: Option D
The braces after return are parsed as a separate block with a label (name:), which is valid code that never runs. Write return { name: name }; (or return { name };).
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!