LearnFrenzy
Sign in Take a free test

Spread and Rest Operators · Find the Error · Question 1

Error: a trailing comma after a rest parameter Answer, explanation & discussion

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

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

main.js
function track(event, ...details,) {
  return `${event}: ${details.join(", ")}`;
}
console.log(track("click", "button", "home"));
  • A SyntaxError: a rest parameter cannot be followed by a comma, even a trailing one Correct
  • B It prints click: button, home
  • C It prints click:
  • D TypeError
Correct Answer: Option A

Trailing commas are allowed after normal parameters, but not after a rest parameter, because nothing may follow it.

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