Reputation: 16587
For example, in test.js
this is allowed (and extremely pointless):
1 + 2;
(function () {});
When executing with node:
$ node test.js
$
The form function () {}
(without parentheses) is allowed in other contexts, for example as an argument to another function.
Why is not the following allowed in the top level of a JavaScript file?
function () {};
Upvotes: 0
Views: 592
Reputation: 887767
A statement that starts with function
is a function statement.
Function statements must be named. (since they create a declaration in that scope)
Upvotes: 4