JavaScript SyntaxError – Function statement requires a name
Last Updated :
22 May, 2023
This JavaScript exception function statement requires a name that occurs if there is any function statement in the script which requires a name.
Message:
Syntax Error: Expected identifier (Edge)
SyntaxError: function statement requires a name [Firefox]
SyntaxError: Unexpected token ( [Chrome]
Error Type:
Syntax Error
Cause of Error: Any function statement in the code that needs a name. Just check how functions are defined and if necessary provide a name for it, or if the function in question requires to be a function expression,
Example 1: In this example, the function name is provided, So the error has not occurred.
Javascript
let GFG = function () {
return 'Hello Geek' ;
}
console.log(GFG());
|
Output:
Hello Geek
Example 2: In this example, the function name is not provided, So the error occurred.
Javascript
function () {
return 'Hello Geek' ;
}
|
Output(in console):
SyntaxError: Function statements require a function name
Share your thoughts in the comments
Please Login to comment...