views:

2993

answers:

6

What version of javascript does Google Chrome support in relation to Mozilla Firefox? In other words, does Chrome support javascript 1.6, 1.7, or 1.8 from Firefox or some combination of them?

+6  A: 

Google Chrome supports up to Javascript 1.7:

<script language="javascript1.7">alert(1.7);</script> - Alerts
<script language="javascript1.8">alert(1.8);</script> - Doesn't alert
Greg
This sounds like the kind of thing that will change over time- are we sure Chrome wont' support 1.8 by the time it leaves beta? But upvote for showing how to check for yourself.
Joel Coehoorn
I'm sure it will support it *eventually* but I don't have any inside knowledge... possibly some Google employees are SO fans and could enlighten us.
Greg
@joel: That's too funny. Have you ever seen a google product leave beta?
Chris Lively
@Chris, Lol, you're right, I've been using gmail beta for years now. Search has left beta, I think, maybe...
Pim Jager
Greg, your test isn't sufficient. Chrome/V8 will run the code in the javascript1.7 section, but it didn't actually test JS 1.7 language features. Those aren't supported in Chrome/V8.
Ben Combee
Google had a purge of Beta markers recently. GMail isn't in beta, nor are most of their other major web apps.
David Dorward
+8  A: 

Google Chrome uses the V8 javascript engine, which currently states that it implements ECMA-262, 3rd edition. This would imply it supports at least version 1.5.

J c
Strange. I thought the `for(var i in objects)` iterator was something not in the third edition, yet it works fine in Chrome and Safari.
skerit
+2  A: 

As a sidebar, the language attribute of the script tag has been deprecated since the html 4 spec, it's recommended to use type attribute instead.

seanb
+8  A: 

While Chrome will execute Javascript marked as "javascript1.7", it does not support JS1.7 features like the "let" scoped variable operator.

This code will run on Firefox 3.5 but not on Chrome using V8:

<script language="javascript" type="application/javascript;version=1.7">
    function foo(){ let a = 4; alert(a); }; foo();
</script>

If you change language to "javascript1.7" and omit the type, it won't run with JS 1.7 features in Firefox 3.5. The type section is necessary.

This seems to be related to a general WebKit bug, https://bugs.webkit.org/show_bug.cgi?id=23097; it may be that Chrome emulates the Safari behavior even though it uses a different engine.

When asked about supporting JS 1.8 features, the V8 team said they were trying to track the version used in Safari so pages would act the same in both browsers.

Ben Combee
thanks so much!
gatoatigrado
That one with let is annoying. I'm forced to use nested closures instead: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Closures#Creating_closures_in_loops.3a_A_common_mistake
Tobu
+1  A: 

Here's a simple Javascript 1.6 feature chrome doesn't run: for each … in

for each (variable in object)
  statement
Tobu
Very good point.
CDR
A: 

yeah, chrome does not run for each syntax with me too ... my chrome version is 6.0.472.63

But does that mean If I will use firefox "for each" will work fine with the browser?