Assigning to empty array/object literals

Michael Day mikeday at
Mon Aug 9 22:21:28 PDT 2010


Firefox 3.6.8 supports the following expressions:

[] = 3;


{} = 3;

Although this object-literal version will trigger a syntax error at 
block scope, and so needs to be written like this:

x = ({} = 3);

In any case, shouldn't both of these expressions be early syntax errors, 
as the left hand side can never be a reference?

For comparison, non-empty array and object literals throw an error:

[1] = 3; // SyntaxError
x = ({foo: 1} = 3); // SyntaxError

Bug in Firefox? Or subtlety of the spec that's gone over my head? :)

Best regards,


Print XML with Prince!

More information about the es-discuss mailing list