JavaScript SyntaxError - Missing } after function body
Last Updated :
22 May, 2023
Improve
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.
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.
function GFG() {
if (true)
return "This is true";
else {
return "This is false";
}
console.log(GFG());
Output(In console):
SyntaxError: Expected '}'