LearnFrenzy
Sign in Take a free test

Functions · Find the Error · Question 4

Error: a function declaration without a name Answer, explanation & discussion

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

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

main.js
function (a, b) {
  return a + b;
}
console.log("ready");
  • A SyntaxError: a function statement needs a name (or must be an expression, e.g. assigned or wrapped in parentheses) Correct
  • B It prints ready
  • C It defines an anonymous function and prints ready
  • D ReferenceError
Correct Answer: Option A

"Function statements require a function name". Name it, assign it (const add = function (a, b) {…}) or wrap it in parentheses to make an expression.

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