But I digress, let’s move on to the main topic at hand, the differences between ES5 and ES6!
- The “use strict” Directive
- Property Getters and Setters
- New Object Property Methods
ECMAScript 6 a.k.a. ES6 a.k.a. ECMAScript 2015 is the latest standard in JS and has brought about some new changes including:
- Fat Arrow Functions —allows for simplified written syntax, and removes the need to use binding of the
thiskeyword as it is already bound lexically. Like so:
- Block-Scope — before ES6 there were only two types of scope: global and function. However block-scope makes variables declared inside a block inaccessible to outside the block or the
- Template Literals — utilize back-ticks (``)instead of double or single quotes. They are formatted by a dollar sign followed by a set of curly braces. Like so:
letkeyword — allows the scope of the variable to be defined by the nearest set of curly braces, which differs from a
varthat defines a variable globally or locally.
constkeyword — acts like a regular variable, except it cannot be altered or reassigned a new value. It is immutable.
- Default Arguments — gives the ability to set a different default value other than
undefinedwhich would be beneficial for testing purposes.
- rest operator — this operator is displayed as
(…)and functions by allowing you to bundle back elements into an array.
- spread operator — this operator is displayed exactly like the rest operator
(…), but does the opposite and expands objects into many elements.
…to name a few.
It is important to note that even though these new features are helpful and beneficial to the landscape of development, there is still resistance in adoption. There are many reasons people do not use ES6, but the most glaring is due to companies declining to use an updated browser to support this format as people are inclined to stick to what they know and work with best. However, as a user of both, I can attest to the greatness that is ES6 and am humbly waiting until I get a chance to learn more on ES7 as I’m sure that will be a wild ride.