So it’s quite common for an engine to implement only the part of the standard.
A good page to see the current state of support for language features is https://kangax.github.io/compat-table/es6/ (it’s big, we have a lot to study yet).
When we use modern features of the language, some engines may fail to support such code. Just as said, not all features are implemented everywhere.
Here Babel comes to the rescue.
Actually, there are two parts in Babel:
First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build systems like webpack provide means to run transpiler automatically on every code change, so that it’s very easy to integrate into development process.
Second, the polyfill.
A script that updates/adds new functions is called “polyfill”. It “fills in” the gap and adds missing implementations.
Two interesting polyfills are:
So, if we’re going to use modern language features, a transpiler and a polyfill are necessary.
Most examples are runnable at-place, like this:
Examples that use modern JS will work only if your browser supports it.
Google Chrome is usually the most up-to-date with language features, good to run bleeding-edge demos without any transpilers, but other modern browsers also work fine.