Internet Explorer Mac numerical property bug

What is going on here?

Using inline object notation with numerical properties throws an error in IE Mac:

var foo = {7:'pass'};

To make matters worse, it treats it as a syntax error and ignores the entire script, and may show a warning dialog, so you cannot use try...catch to avoid this bug (unless you put it inside an eval statement).

What can be done to workaround this bug?

Use numerical string instead of numbers: '7' (in most cases, this is equivalent to using numbers, although strings like '007' will produce the wrong result), or use normal property notation:

var foo = {'7':'pass'};
foo.3 = 'another pass';

Back to HowToCreate | Contact