Skip to content
Related Articles

Related Articles

Improve Article

JavaScript SyntaxError – Missing } after function body

  • Last Updated : 23 Jul, 2020

This JavaScript exception missing } after function body occurs if there is any syntactic mistyping while creating a function somewhere in the code. Closing curly brackets/parentheses must be incorrect order.

Message:

SyntaxError: Expected '}' (Edge)
SyntaxError: missing } after function body (Firefox)

Error Type:

SyntaxError

Cause of Error: Somewhere in the code, there is an error while writing the syntax for a function in the script.

Example 1: In this example, the “}” is missing in else block, So the error occurred.



HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    var GFG_FUN = function() {
      if (true) {
        return "positive";
      } else {
        return "negative";
    };
    document.write(GFG_FUN());
    </script>
</body>
</html>

Output(In console):

SyntaxError: Expected '}'

Example 2: In this example, the function closing bracket is missing, So the error occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    function GFG() {
      if (true)
        return "This is true";
      else {
        return "This is false";
      }
    document.write(GFG());
    </script>
</body>
</html>

Output(In console):

SyntaxError: Expected '}'



My Personal Notes arrow_drop_up