166

A new stable release of Node.js (0.12) has landed recently with an upgraded Google's v8 JavaScript engine, v3.28.73.

What ECMAScript 6 features are currently present in Node.js, without using the --harmony flag?

I have checked several sites claiming to list the ES 6 features but all of them seem out of date - most prominently, this table (Update: now updated with current Node.js status as of 0.12), because several of the features are listed as requiring the --harmony flag while I found some of them being enabled by default (Maps, Sets, Symbols, to name a few). Update: Node specific tables have since been made available

Also, trying to google this information purely for the v8 engine gives too up-to-date information - current v8 release is 4.2.*, which is quite ahead of what Node.js uses.

My hopes are that this question (and its answers) will become a comprehensive summary on what ES 6 features are now available to Node.js developers.

ES 6 features enabled in Node.js 0.12 I currently know of:

  • Maps, Sets / WeakMaps, WeakSets
  • Symbols
  • Object.observe
  • Promises
  • Number
    • .isInteger
    • .isSafeInteger
    • .isNaN
    • .EPSILON
    • .MIN_SAFE_INTEGER
    • .MAX_SAFE_INTEGER
  • Math
    • .clz32
    • .imul
    • .sign
    • .log10
    • .log2
    • .log1p
    • .expm1
    • .cosh
    • .sinh
    • .tanh
    • .acosh
    • .asinh
    • .atanh
    • .trunc
    • .fround
    • .cbrt
    • .hypot
Mchl
  • 61,444
  • 9
  • 118
  • 120
Robert Rossmann
  • 11,931
  • 4
  • 42
  • 73
  • 9
    *"My hopes are that this question (and its answers) will become a comprehensive summary on what ES 6 features are now available to Node.js developers."* - The chances are that it will simply become a disorganized mess ... that is just as out-of-date as all of the other resources!! Unless you 1) self answer and 2) take the time to curate the other answers into yours. If you are prepared to do that work, then it might be more appropriate to do it in a blog. – Stephen C Feb 07 '15 at 23:47
  • 2
    Or just switch to [io.js](https://iojs.org/) (which ships with a far more up to date V8 version) and keep an eye on the [ES6 on io.js page](https://iojs.org/es6.html). – Fabrício Matté Feb 07 '15 at 23:53
  • I don't have a blog (- not sure if happy or sad smile here -). The answer that gets all of the features listed for the versions mentioned (they are not infinite!) will get accepted, be it an answer of mine or someone else's. Alternatively, the answer with most upvotes wins. – Robert Rossmann Feb 07 '15 at 23:53
  • @StephenC Actually I think this is a good question. Specially considering the fact that node documentation is really poor. Let's see it'll become disorganized mess or not. We can't foresee the future. – alexpods Feb 07 '15 at 23:53
  • 2
    Curated ES6 compatibility table: http://kangax.github.io/compat-table/es6/ – Fabrício Matté Feb 07 '15 at 23:56
  • Kangax's compat tables appear to have been [last updated with Node 0.11.14](https://github.com/kangax/compat-table/blob/afd609160bc846bbe96b15bb563285bc9d6ba455/data-es6.js#L307-L313), but they are [open source](https://github.com/kangax/compat-table/) and could be run with 0.12 manually. – Jonathan Lonowski Feb 07 '15 at 23:58
  • 2
    @JonathanLonowski interesting, it is odd that I can't find an issue/PR regarding Node 0.12. **edit:** filed an [issue](https://github.com/kangax/compat-table/issues/427). – Fabrício Matté Feb 08 '15 at 00:00
  • 1
    @RobertRossmann - Anyone can have a blog. I'm not doubting your goal. It is just that I don't think this will work ... unless someone (i.e. >>you<<) puts in the >>effort<< to make it work work. – Stephen C Feb 08 '15 at 00:00
  • You might find this useful: [ECMAScript compatibility table](https://kangax.github.io/compat-table/es6) –  Jul 24 '16 at 18:08
  • See http://node.green/ – Michał Perłakowski Apr 08 '17 at 15:54

2 Answers2

250

Features without --harmony flag:

I thinks that's all that we have without --harmony flag.

Features with --harmony flag:

I think that's all. Maybe if I forgot something - I'll add it later to the list.

alexpods
  • 47,475
  • 10
  • 100
  • 94
  • 8
    This is exactly the kind of answer I was hoping to get - clean, and with links to docs/examples! Extra points for listing features under the `--harmony` flag.:) – Robert Rossmann Feb 08 '15 at 18:21
  • 2
    String templates are out with or without `--harmony`? As in the back tick `${varname}` string syntax? – Sukima Apr 22 '15 at 22:44
  • 5
    @Sukima Node v0.12 does not support [template strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings), nor with `--harmony` flag, nor without it. But `iojs` supports them without need of any flags. – alexpods Apr 23 '15 at 02:36
  • 1
    Does nodejs have this documented anywhere? It is very useful. – Justin Hamade Aug 10 '15 at 17:11
  • Hmm... My run failed with a constant without the harmony flag just now. Node v0.12.2 – JonRed Aug 29 '15 at 22:19
  • 1
    @JonRed Maybe your run failed by another reason, not because of a constant. I have just tried it and my run works pretty well. – alexpods Aug 30 '15 at 11:43
  • @alexpods - tested again this morning with a basic example, you're dead right. Thank you. – JonRed Aug 30 '15 at 18:21
  • Per [this thread](https://esdiscuss.org/topic/an-update-on-object-observe), Object.observe is going the way of the dinosaur – Sarsaparilla Nov 05 '15 at 16:54
  • @HaiPhan Thanks for reminding! I've updated the answer. – alexpods Nov 05 '15 at 17:33
4

ES6 features trickle down to Node in phases. Node uses Google's V8 as the JavaScript engine. A feature being supported in Node means it first has to be implemented in V8 and then Node team has to incorporate it in Node.js.

The team at Google releases a new version of V8 roughly every six weeks, and then it's up to the Node team to take it into use.

Manually curated lists of language features are nice but can become outdated quickly. Node 0.12 is not that in flux anymore, but typically manually curated list becomse obsolete as soon as a new version of Node is rolled out.

Here are two alternate ways to check what features a Node version supports, without relying on a static list. For further reading and more detailed examples of using these, you can check "How to check if Node.js supports ES 6 language feature"

#1 Easy - compatibility table

A dynamically generated list that relies on small tests to confirm the presence of a language feature stays better up to date. One such popular list is kangax.github.io/compat-table/es6/. We are interested only in Node features, so you can use

http://node.green

that leverages the same data as the kangax site.

#2 Hard - backtrack V8 version

Node uses V8 engine, so determining which version of V8 is included in Node tells us what ES6 language features are supported. You can find out which version of V8 was bundled in Node with node -p process.versions.v8.

$ node -p process.versions.v8
4.6.85.31

Then using Google's V8 project resources you can find which features are implemented in each version. The V8 project keeps an issue tracker where you can find ES6+beyond features marked with the harmony label.

pspi
  • 11,189
  • 1
  • 20
  • 18