LearnFrenzy
Sign in Take a free test

JavaScript Basics · Find the Error · Question 1

Error: unexpected end of input Answer, explanation & discussion

  • Find the error
  • Easy
  • 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 add(a, b) {
  return a + b;

console.log(add(2, 3));
  • A a and b must be declared with let
  • B SyntaxError: the function body is never closed – a } is missing after return a + b; Correct
  • C console.log cannot be called after a function
  • D add must be declared before it is called
Correct Answer: Option B

The parser reaches the end of the file still inside the function body: "SyntaxError: Unexpected end of input". Add the closing brace after the return statement.

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