48

Which 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 which Firefox also supports or some combination of them?

eohomegrownapps
  • 104
  • 1
  • 12
brad
  • 73,826
  • 21
  • 73
  • 85
  • 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 Nov 18 '08 at 22:01
  • This is really weird, my plugin's js have issues with chrome, but working perfectly on other browsers. `onclick()` not working in `select-box`. i tried `onchange()`, `onblur()` , `onfocus()` but still not working in chrome. – Frank Oct 02 '12 at 08:39

6 Answers6

42

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
  • 16,831
  • 6
  • 41
  • 42
  • 4
    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 Mar 16 '10 at 21:39
18

This thread is still relevant. As of 2012, Chrome supports most of Javascript 1.6, not including string and array generics. It supports none of 1.7. It supports reduce and reduceRight from 1.8, all of 1.8.1, and Getters and setters and all the non-version specific things listed on this page. This page is linked from the Mozilla Developer Network, which specifies the versions of javascript, found here.

Case
  • 1,848
  • 21
  • 32
14

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
  • 6,387
  • 3
  • 29
  • 29
  • 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. – Jelle De Loecker Jul 19 '10 at 12:25
  • 3
    @skerit by saying "it implements", at least all of the features in ECMA-262 v3 is available. They are free to add other features, including the one you mentioned. – syockit Jun 02 '11 at 20:08
11

Here's a simple Javascript 1.6 feature Chrome (and V8 users, like node.js) won't run: for each … in

for each (variable in object)
  statement

As it is JS 1.5 (per J c's answer) is the only version Chrome claims to completely implement.

In fact the Chrome team has mostly aimed for compatibility with Safari (most prominent Webkit user at the time), and refused features on those grounds.

Tobu
  • 24,771
  • 4
  • 91
  • 98
  • 1
    Not supported in Chrome 16.0. Wasted an hour wondering why code was not working... – SabreWolfy Feb 07 '12 at 15:12
  • You're not using forEach correctly. Check the syntax here: http://robertnyman.com/javascript/javascript-1.6.html – Case Mar 14 '12 at 03:39
  • @Sharon that's a different feature. My answer is framed by the question; I picked a JS 1.6 feature that is missing in Chrome. Link if you missed it: https://developer.mozilla.org/en/JavaScript/Reference/Statements/for_each...in#Syntax – Tobu Mar 14 '12 at 22:05
  • This doesn't quite answer the question. – Dan Dascalescu Nov 07 '12 at 05:04
7

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
  • 316,276
  • 54
  • 369
  • 333
  • 3
    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 Nov 18 '08 at 21:44
  • 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 Nov 18 '08 at 21:45
  • 5
    @joel: That's too funny. Have you ever seen a google product leave beta? – NotMe Nov 18 '08 at 21:45
  • @Chris, Lol, you're right, I've been using gmail beta for years now. Search has left beta, I think, maybe... – Pim Jager Nov 18 '08 at 23:31
  • 11
    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 Jul 14 '09 at 13:27
  • Google had a purge of Beta markers recently. GMail isn't in beta, nor are most of their other major web apps. – Quentin Jul 14 '09 at 13:28
  • 2
    I will point out that my current version of chrome still doesn't support things like Iterator or the yield keyword – George Mauer May 17 '11 at 19:21
  • 6
    This answer is not correct. Although V8 will run code in a javascript1.7 tag, it DOES NOT include any 1.7 specific features as of yet. – GAgnew May 25 '11 at 20:29
4

This is an old thread, however here goes. Google Chrome does not respond to the following

function foo(){
  let a = 4;
  alert(a);
}
foo();

hence it does not support JavaScript 1.7

Tobu
  • 24,771
  • 4
  • 91
  • 98
  • there's a couple of other things i had trouble with in javascript 1.7 on chrome, like even accessing global variables and such – user151496 Oct 27 '14 at 10:07