A quick overview of the new functionalities that are being shipped with ES6
There has been an inception of the 6th edition of the language and here is a quickie for the noobs
I have “cheery-picked” a few features to get yourself introduced to the new capabilities it provides a developer:
The new standard introduces the new let keyword, which lets you declare and initialize variables in the scope of a block. A block can be a programmatic enclosure such as a statement, an expression or function.
Using the let keyword leads to cleaner, more scope controlled and usable code. The difference between let and var is in the scope, for example a local variable defined by the var keyword can be used in the entire enclosing function, while variables defined by let only work in their own block.
As you might expect from the sound of the keyword itself that it makes it possible to declare constants ( immutable variables).
Though, constants cannot be considered to be fully immutable, because if the constant holds an object the properties and methods can still be altered
This featues let us write anonymous functions in a better manner. Instead of writing the function keyword we can removed it with the =>. This automatically return the resolved value of the statement that comes right after.
ES6 comes with a new operator called spread signified by
…, which is generally a sign to place multiple expected items. A better way to understand it is by an example where you add or
spread an array to include more elements.
- Default Parameter Value(s)
In ES6 we can add default values to parameters, which makes life much easier, especially if you’re writing more graceful and defensive code.
- Rest Parameters
The rest parameters come in handy when you do not know how many arguments will be passed in a function.
- for…. of
If you’ve know loops such as for..each, this will make sense. When we use the for…of statement, the code inside the block is executed for each element of the iterable object.
- Template Literals
Template literals allow us to easily create strings out of templates which can embed different content.
I guess this has to be one of the best features of ES6. Just like what you have done with AMD using RequireJS before, now ES6 comes with modules as native features. The idea here is to define each module in its own file, then use to “export” it out to other files, and accordingly “import” them from other files.
I guess that was good enough to get started.
Here is a good documentation for most of the features if you would like to dwell into ES6 further
Plus, here is a compatibility chart, which I believe is really import to keep a track on to know exactly when is the “future”.