Open In App

JavaScript SyntaxError – Missing } after function body

Last Updated : 22 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Javascript




let GFG_FUN = function () {
    if (true) {
        return "positive";
    } else {
        return "negative";
    };
console.log(GFG_FUN());


Output(In console):

SyntaxError: Expected '}'

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

Javascript




function GFG() {
    if (true)
        return "This is true";
    else {
        return "This is false";
    }
console.log(GFG());


Output(In console):

SyntaxError: Expected '}'

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads