Randomblue
Randomblue

Reputation: 116433

SyntaxError for function(){}()

Please see this fiddle. For me, it's just a self-executing empty function:

function(){}()

Google Chrome 16.0.912.4 dev-m returns the error:

Uncaught SyntaxError: Unexpected token (

Why? This is especially strange because adding extraneous brackets will remove the error:

(function(){})()

Upvotes: 3

Views: 795

Answers (1)

Raynos
Raynos

Reputation: 169551

ExpressionStatement :

[lookahead ∉ {{, function}] Expression ;

Because a function () {}() is not a statement as defined in ES5.1

And a valid program has to be a statement.

Expression Statement.

however the following

!function () {}();

is a valid statement, so is using () and so is var ret = function () {}()

Upvotes: 7

Related Questions