Function inside if statement?

Garrett Smith dhtmlkitchen at
Tue Feb 5 15:45:13 PST 2008

if(a) {
 function b(){ }

A block can contain statements. A statement can't start with the
function keyword.

Mozilla's Core JavaScript guide explains that of |b| should be
evaluated as a functionExpression, but this isn't right.

What should the above code do?

Should it be:

if(a) {
 (function b(){ });

SHould it be a function declaration, just like a variable statement?

if(a) {
 var b;

Spidermonkey treats |b| as a function declaration as a statement (example).

No imlementations I know throw a SyntaxError; instead, the behavior is


More information about the Es4-discuss mailing list