39

According to this thread from the old Google Group, Apps Script is based on ECMA-262 3rd Edition.

This would seem to be supported by the fact that auto-completion in the editor displays 3rd Edition array functions.

However the following code runs perfectly well, which casts doubt on the matter:

var array = [
  1,2,3,4,5
];

Logger.log("forEach:");
array.forEach(function (item,idx,arr) {
  Logger.log(item); 
});

Note the use of ECMA-262 5th Edition Array function forEach.

Would someone authoritative mind giving a definitive answer on why this is the case? And whether it's safe to rely on all 5th Edition features or a sub-set that have been implemented and seem to work?

Rubén
  • 34,714
  • 9
  • 70
  • 166
chrisbateskeegan
  • 1,013
  • 1
  • 11
  • 14

2 Answers2

32

The documentation says that the old runtime is based on Mozilla's Rhino JavaScript interpreter which provides a subset of ECMAScript 5 and is based on 1.6, with a smattering of 1.7 and 1.8.

The new Apps Script runtime is supported by the V8 runtime with few exceptions like E6 Modules.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 3
    As of February 2020 Apps Script supports V8 runtime and "modern ECMAScript features": https://developers.google.com/apps-script/guides/services/#modern_javascript_features – Kos Feb 06 '20 at 19:09
2

From Built-in Google Services

Apps Script supports two JavaScript runtimes: the modern V8 runtime and an older one powered by Mozilla's Rhino JavaScript interpreter.

The V8 runtime supports modern ECMAScript syntax and features. The Rhino runtime is based on the older JavaScript 1.6 standard, plus a few features from 1.7 and 1.8. You can freely choose which runtime to use with your script, but the V8 runtime is strongly recommended.

Rubén
  • 34,714
  • 9
  • 70
  • 166