I just tried in Firebug console,
let (X=10) X/2
and
[x,y]=[y,x]
These are features supported by SpiderMonkey, I guess V8 has its own share.
Where can I learn of features that are not yet included in ECMAScript, but work in various browsers? Is there a place where these are collected together?
ECMAScript 6 (a.k.a. ECMAScript 2015) is the current standard for JavaScript, but engines have yet to implement it completely:
Table showing what ES6 features are supported where: http://kangax.github.io/compat-table/es6/
Three books on ES6 that are free to read online (buy them I you like them!):
Read Understanding ECMAScript 6
Exploring ES6
JavaScript Allongé, the "Six" Edition
ES6 in bullet lists
Starting with ECMAScript 2016, there will be yearly releases and a new release process:
Blog post explaining the new release process and the features that are candidates for ES2016: http://www.2ality.com/2015/11/tc39-process.html
Official list of proposed features (that may or may not be accepted for the ECMAScript standard): https://github.com/tc39/ecma262
Feature table for ES2016: http://kangax.github.io/compat-table/es7/
If you want to use any of the new features even on older engines, you can transpile them to ES5 via Babel: https://babeljs.io/
And here is a article covering various resources around Harmony/ES6/Javascript.next:
http://addyosmani.com/blog/ecmascript-6-resources-for-the-curious-javascripter/
That first feature is known as a "let expression" and it is nonstandard; it was dropped from Firefox 41, and the similarly nonstandard "let block" was dropped from Firefox 44: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Non-standard_let_extensions
I was surprised to find that this particular non-standard JS was not mentioned in Kangax's table, but I guess he had to restrict this list to non-standard JS extensions that are supported by multiple engines: https://kangax.github.io/compat-table/non-standard/
If you want to go deeper down the rabbit-hole, and Kangax and MDN haven't satisfied your curiosity, this old reference may tell you about curiosities in older browsers: help.dottoro.com/ljsdaoxj.php
Beyond that, the browser-makers usually document the quirks of their own browsers (MDN is also good about documenting non-Mozilla quirks, but it's not perfect); speaking of quirks, Peter-Paul Koch documents both standard and non-standard DOM methods here: quirksmode.org/dom/
Anyway, these aren't just "not yet" in the standards, but likely "not ever" and you shouldn't use them in your own code.
For current ECMAScript 264 implementation here is a list of features supported by different browser vendors:
http://kangax.github.com/es5-compat-table/
For the next generation ECMAScript Harmony some resources:
http://addyosmani.com/blog/ecmascript-6-resources-for-the-curious-javascripter/
http://kangax.github.com/es5-compat-table/es6/
Related
When you crate a new Google Apps Script, it seems to support the v8 runtime by default. The documentation states:
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 V8 runtime documentation states:
You can use modern ECMAScript syntax in scripts that are powered by the V8 runtime. This syntax includes let, const, and many other popular features.
In both cases, they are very vague as to which ECMAScript version is supported, simply stating "modern ECMAScript syntax". This is problematic because there are 7 versions that were released between 2015 and 2021. Thus "modern" could refer to any one of these versions.
For example, I could easily assume that "modern" refers to the latest, 12th edition (2022) of ECMAScript, and end up writing code like this:
let a = 1_000;
However, attempting to use that syntax leads to the error:
Syntax error: ParseError: Unexpected token ILLEGAL line: ...
Rather than manually go through each of the remaining 6 versions until I find the latest one supported, it would be great to find documentation that explicitly states which ECMAScript version is supported.
Note: The previous related question (Which Edition of ECMA-262 Does Google Apps Script Support?) is not helpful since those answers also refer to "modern ECMAScript" rather than a definitive, specific version.
Which version of ECMAScript is supported by the V8 runtime?
There is some nuance here:
Which version of V8 does Google Apps Script use?
A reasonably recent version, and it gets updated every so often. I believe the idea is to track or slightly lag behind stable Chrome releases, but (as with any large project updating its dependencies) there may occasionally be hiccups/delays. Right now it should be somewhere in the 9.x version range. (For future readers: I expect this statement to be outdated before 2022 is over!)
Which version of ECMAScript does the Google Apps Script V8 Runtime Support?
I suppose if there was a simple answer to this, you'd find that in the documentation. As #Kaiido said in comments, JavaScript engines implement new JavaScript features one by one (rather than EcmaScript versions). So, for browsers just like for environments like GAS, it usually makes more sense to ask "is feature X supported?", because it may well be that some, say, ES2020 features are still missing but some ES2021 features are already available.
Why does let a = 1_000; produce a Syntax Error?
Well, the V8 version that GAS uses is sufficiently new (by at least two years) to support it; but the overall GAS experience depends on more than V8: the editor is parsing the entered source in order to provide help or highlighting or error checking or whatnot. It looks like the GAS team is aware that certain features aren't supported yet by the components responsible for that, and is actively working to remedy that. (I have no idea what the timeline is.)
Why does let a = 1_000; produce a Syntax Error?
Just to expand on #jmrk's answer about new features not supported by the parser.
function test2564(){
//let a = 1_000; throws syntax error by the parser
console.info(eval(`1_000`));// correctly logs 1000
}
The underlying V8 engine is good and supports the latest features, but the parser won't allow you to save or execute the project with those features, as it considers them as syntax errors.
I've been working with KoaJS for a while, and we can easily use the 'let' keyword and the generators when using the --harmony flag but I couldn't find how much support for does the node v0.11.x provides while using the same.
I tried using the default value argument initialization but couldn't succeed.
Is there any source available which can list the no of features of ECS 6 supported in node v0.11.x using the harmony flag? Or if there is any npm module available for node that might allow me to use the same?
Thanks in advance.
With regards to your second question, yes, there is es6-module-loader.
For a long list of transpilers, shims, and other tools for using full ES6 features now, see addyosmani's ECMAScript 6 Tools page.
As for native ES6 support in node.js, V8 officially implements "ECMAScript" but AFAIK the V8 project doesn't release a spec of their implementation.
However there are some sources of useful information out there.
Here's a brief overview of ES6 in node.js v0.11.6.
You may want to determine the version of V8 that your version of node.js uses.
See the node.js blog for recent changelog info.
It can also be useful to find the version of V8 used in a given Chromium release.
The Chrome release notes can be found here.
Keep in mind that different flags can be set for the same version of V8.
Chromium and node.js both have ways to set flags in V8 related to ES6 support.
Here are two tables that list ES(6) feature support across implementations:
http://pointedears.de/scripts/test/es-matrix/
http://kangax.github.io/compat-table/es6/
This MDN page lists a set of reference articles for ES6 language features.
At the bottom of each one you can see the status of Chrome support for that feature (and using V8 versions determine the support in node.js).
Finally, the V8 issue tracker
provides a list of issues related to ES6 features, many of which have been implemented and their issues closed.
You can use ~96% of ES6 features in Node.js 6. You can review support for all versions on http://node.green/
This does not concern node 0.11, but in the current 5.8.0, you can use --harmony_default_parameter.
It it scheduled to be included by default in v6.0.
I was looking at Mozilla Developer Documentation on Javascript. Is it Mozilla's interpretation of the ECMAScript standard or is it documenting how they have implemented Javascript in Firefox?
Basically, I want to know whether their documentation is valid across all browsers or just Firefox.
It's both, basically. From JavaScript/Reference/About:
The JavaScript Reference serves as a repository of facts about the
JavaScript language. The entire language is described here in detail. […]
Recent versions of Mozilla-based browsers support newer versions of
JavaScript. […]
Browsers that do not support at least JavaScript 1.5 are very rare
today, since JavaScript 1.5 was introduced back in 1999. If you're
interested in historic information, please refer to the Wikipedia
article on ECMAScript.
JavaScript documentation of core language features (pure ECMAScript,
for the most part) [consists of the Guide and the Reference].
It is definitely a reference about the Mozilla implementation(s) of JavaScript, which today covers all of EcmaScript 5.1 features. They're well documented, also containing information about bugs in older Mozilla implementations and in relevant other engines. Each article also lists cross-browser support in a table, though these are sometimes not correct and/or exhaustive.
The reference also includes documentation of proprietary Mozilla features and of their draft implementations for upcoming standards. These are properly marked as such, usually with the non-standard-tag.
Also, don't forget that it's a wiki!
as Alex K has said in his comment
It documents Geko, the mozilla implementation of JS which also includes all the non-standard functionality they have included
It is also an excellent reference for standard js api calls, but should always be used with a slight caveat of, it is the Geko implementation so may not behave as described, but generally it does in my PERSONAL experience
Is there a way to alert the supported EcmaScript version of the current environment where I run my JavaScript?
Short answer: No.
Long answer: First of all, browsers doesn't implement ECMAScript but a language based on that specification (e.g. JavaScript for Firefox, JScript for Microsoft). Often, they can implement part of the standard, and complete the standard in a next version of the language (it happened in JavaScript 1.8 / 1.8.1 / 1.8.5 about ES5 for example, see New in JavaScript).
Plus, they could anticipate the standard: see for...of or let, that Mozilla has since years, that are part of ES6.
So, you can't really say what ES version is supported by your environment; what you can do is testing the functionality you are interested in, and use them. In most of the case, we apply a shim, where is possible, to emulate that functionality, like for ES5.
I want to know which sites can give me information on the list of JavaScript functions that are supported by IE/Firefox/Opera/Safari.
Take a look at quirksmode
and in the Compatibility Master Table
you will get a detailed listing.
Perhaps not a direct answer to this question, but never-the-less I think this is useful to know about: You can use the Sputnik JavaScript Conformance tool in Google Labs to check ECMAScript conformance in browsers:
Sputnik is a JavaScript conformance
test suite containing over 5000 tests.
It tests how well a JavaScript
implementation adheres to the ECMA-262
specification version 5, looking only
at those features that were also
present in the previous version,
version 3, and not the new features
added in version 5.
There are several sites for that but you'll probably find that none are absolutely complete, so it is worth checking out each of them
quirksmode.org compatibility tables
sitepoint JS reference (work in progress)
Mozilla MDC reference (mozilla only but worth mentioning)
This looks useful http://kangax.github.com/es5-compat-table/