Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ECMAScript 6 features available in Node.js 0.12

People also ask

Does Node 12 support ES6?

Node js doesn't support ES6 import directly. If we try to use import for importing modules directly in node js it will throw out the error. For example, if we try to import express module by writing import express from 'express' node js will throw an error as follows: Node has experimental support for ES modules.

What version of ECMAScript does Node support?

The result is that currently Node LTS (16.13. 1), includes V8 9.4, which supports all the ECMAScript 2022 features.

Can I use ES7 in Node?

The exponentiation is the last ES7 feature that was added to Node so if you want to use all ES7 features with no flags then you need at least Node 7.0. If you can use the --harmony flag then you can use at least Node 6.5. The 6. x version is LTS (Long Term Support) so you may want to prefer it over 7.


Features without --harmony flag:

  • "for-of" loop
  • Map, Set, WeakMap, WeakSet (already specified in question)
  • Symbol (already specified in question)
  • Promise (already specified in question)
  • Array methods:
    • .keys()
    • .values()
    • .entries()
    • [Symbol.iterator]
  • Object:
    • .observe() (initially was planned for ES7, but was removed from the spec entirely on November 2, 2015)
    • .is()
    • .setPrototypeOf()
    • .getOwnPropertySymbols()
    • .getNotifier() (not es6, example here)
    • .apply() and .call() (not es6, same purpose as Funciton.prototype.call and Function.prototype.apply)
  • Number properties and methods (already specified in question)
    • .isInteger()
    • .isSafeInteger()
    • .isNaN()
    • .isFinite()
    • EPSILON
    • MIN_SAFE_INTEGER
    • MAX_SAFE_INTEGER
  • Math methods (a lot of them) (already specified in question)
  • constants

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

Features with --harmony flag:

  • generators
  • arrow functions (without need of --harmony_arrow_functions flag in contrast to io.js)
  • let variables - only in strict mode
  • Binary and octal literals
  • String methods:

    • .contains() (was replaced by includes() in actual ES6 specification)
    • .startsWith()
    • .endsWith()
    • .codePointAt()
    • .repeat()
    • .normalize()
    • String.fromCodePoint
  • Proxy (behind the --harmony-proxies flag)

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


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.