JSLint will throw the "Missing name in function statement" error when it encounters the function keyword, where it would be parsed as a statement, followed immediately by an opening parenthesis. In the following example we attempt to define a function but forget to give it an identifier:
This error is raised to highlight a JavaScript syntax error. Your code will not run unless you fix this issue.
The ECMAScript grammar states that a function statement (or declaration) has to have an identifier (ES5 §13):
FunctionDeclaration :
function Identifier ( FormalParameterListopt) { FunctionBody }
Notice that the Identifier part of the grammer is not optional. Compare this to the grammar for a function expression:
FunctionExpression :
function Identifieropt ( FormalParameterListopt) { FunctionBody }
This time, notice that the identifier is optional. This optional identifier in function expressions is what makes it possible to create anonymous functions. However, in our example above, the code is parsed as a statement rather than an expression. To fix the issue, give the function an identifier:
Alternatively, make sure the code is parsed as an expression, rather than a statement. There are numerous way of doing this, but in our example the only one that really makes sense is to assign the anonymous function to a variable (don't forget the semi-colon):