Let and Const keyword
‘const’ is also like ‘let’, so it also has block scope. The only difference is- it can’t be reassigned and can’t be re declared as well.
Hence, ES6 provides us a way to have true block scoping. Cheers!!!
Examples of both ‘let’ and ‘const’ keywords are shown here –
Instead of function keyword, we can now use =>(arrow symbol for functions). There is a difference though, arrow functions do not bind its own ‘this’. It has ‘this’ scope of the parent so we don’t need to use bind or assign ‘this’ to some other variable and use it. In addition, if a function has just one line no brackets or return statement is required.
This is probably the most awaited feature in ES6. Now we can write classes without using inheritance patterns. We can also use constructor. Most of all, classes can be extended with ‘extend’ keyword. Also, the parent class’s constructor can be called with ‘super’ keyword.
Now we don’t have to use ‘+‘ operator to combine strings and variables. Instead, we can use template variables which accomplish this task in a much cleaner syntax.
Multi line strings
Wring multi line strings is a lot better in ES6. We don’t have to use ‘+’ operator or use ‘/n’ to write multiline strings.
These are defined in the definition of the function. If params are not passed then default params are used, .
This is very useful stuff which I find in ES6. If we want to get some params from objects and assign it to variables, in a typical scenario we would have to go one by one and assign it to all the variables. Using destructuring it is much cleaner syntax, magically we can just bring properties of objects with variables of the same name.
Rest parameter is to handle any number of params in a function. Single REST param can have multiple values. Unlike previously, where we had to use array to pass the value.
Syntax is same as rest params but It basically expands the values in object or array. This example is self explanatory–
Promises in ES6
We do not need promise libraries no more.We can use inbuilt promises in ES6 instead of libraries like ‘q’.
Finally in addition to these features, are other new features in ES6 like Modules, Symbol types etc. Complete list of features –https://babeljs.io/learn-es2015/