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.
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.
function () {
return 'Hello Geek' ;
} |
Output(in console):
SyntaxError: Function statements require a function name