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 his own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like webpack or brunch provide means to run transpiler automatically on every code change, so that doesn’t involve any time loss from our side.
Second, the polyfill.
There’s a term “polyfill” for scripts that “fill in” the gap and add missing implementations.
Two interesting polyfills are:
So, we need to setup the transpiler and add the polyfill for old engines to support modern features.
If we orient towards modern engines and do not use features except those supported everywhere, then we don’t need to use Babel.
Most examples are runnable at-place, like this:
Examples that use modern JS will work only if your browser supports it.
```offline As you're reading the offline version, examples are not runnable. But they usually work :)
Chrome Canary is good for all examples, but other modern browsers are mostly fine too.
Note that on production we can use Babel to translate the code into suitable for less recent browsers, so there will be no such limitation, the code will run everywhere.