ES6 is the 6th edition of ECMAScript, standardized in 2015. It brings many engrossing features that were not seen in previous versions like ES5. For instance, let and const, they are blocked scoped declarations and thus not prone to the common errors caused by misunderstanding.
ES6 will tackle many of the core language shortcomings addressed in TypeScript and CoffeeScript. Let us go through the features of ES6 that gives it an edge:
Arrows are a function shorthand using the => syntax. There is a similarity between the syntactical features of C#, Java 8, CoffeeScript and ES6. Both statement block bodies and expression bodies are supported by them, which return the value of expression. Unlike functions, arrows share the same lexical this as their surrounding code.
Enhanced Object Literals
Purpose of object literals is to support setting the prototype at construction, shorthand for foo: foo assignments, defining methods, making super calls, and computing property names with expressions. When combined they bring object literals and class declarations closer together, and benefits object-based design from some of the same conveniences.
In ES6 modules provide a course to load and manage dependencies through the new import export keywords. Even after having good solutions like 3rd party libraries in ES5, modularity remains an important concept for large applications. The following goals of this version make it an indispensable language feature:
- Anticipate and prevent need of globals
- Easy reallocation from global code to modular code
- Smooth interoperability with existing JS module systems like AMD, CommonJS, and Node.js
- Quick collation
- Standardized protocol for sharing libraries
- Compatibility with browser and non-browser environments
- Easy asynchronous external loading
Scoping becomes an ambiguous affair for developers who has background of C/C#/Java. Hoisting can add to that confusion. ES5 lacked a very essential feature of block scoping, which deranked it in comparison to ES6. Though need became the mother of invention and block scoping came into the scenario. ES6 emerged out with this feature, block scoping can be achieved through using let keyword.
The above features of ES6 are potent enough to make us pursue it.But let us evaluate the real scope of this technology before plunging into it.
The expanse of ES6 right now is limited to the newest browsers, but soon it is going to expand its stretch as it presents a host of elegant solutions and syntax that many developers find appealing and useful. And if developers want to ensure of ES6 code in older browsers a compiler named Babel can transform ES6 code into ES5 code as part of a build step. Once when all the browsers start implementing the specification, this build step can be removed.