ES6 features that every developer should know

ES6, A bright new future is coming

A lot of new stuff is introduced in ES6 or ES 2015 which is a newer version of JavaScript. Below is the list of some important features –

Let and Const keyword

‘let’ keyword provides true block scoping for JavaScript. Scopes do not have any impact on ‘var’. On the other hand, if a variable is defined with ‘let’, then it is only defined within that scope.

‘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 –

Arrow functions

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.

Classes

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.

Template strings

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.

Default params

These are defined in the definition of the function. If params are not passed then default params are used,  .

Destructuring assignment

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 parameters

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.

Spread syntax

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/

Leave a Reply

Your email address will not be published. Required fields are marked *