views:

30

answers:

2

Suppose there is a piece of JavaScript code that is supported by different browsers, for example IE and Firefox. Would the JavaScript parsers of the different browsers generate the same output (i.e., the same AST)?

+2  A: 

Would the JavaScript parsers of the different browsers generate the same output

No, Not always, different browser have different javascript Parser, IE have JScript Engine and Mozilla have its own Javascript Engine.

For example, if you run following code

'x'.split(/(x)/).length

Firefox return 3, while IE return 0

See

S.Mark
Hi Mark, Codeka:Wondering the different results of your guys' examples are caused by the difference of their interpreters or their parsers?
Paul
S.Marks' differences comes from a different implementation of the split() function, so you could say that's in the standard library. Mine would be because of a difference in the parser (i.e. assigning a different meaning to the token 'e')
Dean Harding
+2  A: 

Theoretically yes, but in practise they don't. For example the following code is treated slightly different in IE vs. Firefox:

var e = 10;
try
{
    e.something();
}
catch (e)
{
}

alert(e);

IE will print "[object]" whereas other browsers will print "10" because browsers other than IE assume the catch clause is a "local" variable and a different scope to the outer scope.

Dean Harding