5 ES6 Features that every JS Developer should know

1. let and const
In ES5 variable can be declared with only var keyword and which is not secure and it has a possibility to leak private data but we can use let and const keyword instead of var
it is a scope variable that means it works based on scope that means if a variable declares in a for loop the scope of that variable is limited to that scope and if you want to change the value of a variable declared with let, you can change.
It is also a scope variable, but the value of a variable assigned with the const keyword is immutable that means the value remains constant and cannot change further time and it is a very useful keyword when we want some immutable data.
An example of let and const is below:

2. Template string
In ES5 we can write string with a single quote or double quote and if we want to add strings with many we have to use plus operator and for writing multiple lines using single or double quote we have to use a new line operator not only that we can’t use variables in the string value which are declared with a single or double quote and it was boring feature for JS developer and for that ES6 comes with another one awesome feature called template string

Usage of the template string
We can add many more strings and we don’t need to use + operator for that
We can write multi-line strings without using a new line operator
If we want to use variables in the string we can easily do this
See below how template string works

3. Arrow function
The most awesome feature of ES6 is, arrow function and it is so powerful function and better than regular function here some comparison between regular and arrow function
To create a regular function we have to write a function keyword but we can create an arrow function without writing the function keyword. If we write a very simple function and return a result, in regular function, we have to write multi-lines of code, but in arrow function, we can write the simple function in just one line and for that, it’s called one-line mini function.
When talking about using callback functions, array methods like map, reduce or forEach the arrow function is best instead of using regular function
An arrow function cannot be used as a constructor but a regular function can be.
See some examples below

4. Class
In ES5, there are no classes we have to create a class using function keyword and that is not more informational however in ES6 comes with another awesome feature called, class keyword using class keyword we can easily create a class and this is more informational than ES5
Now let’s talk about when to use class in our JavaScript code
When we need to make some similar type of object, we can solve the issue easily using a class. In ES5 we had to write similar object individually which is more memory consumption and it makes codes larger and complex so the class keyword is here to solve the issue the example is below:

5. Destructure
In ES6 destructuring is another magnificent feature using this feature we can unpack values from an array or object or distinct variables and it is a more useful feature for JavaScript developer, some features of destructing are following
It can extract multiple properties from an array or an objects
And can also access properties from nested objects
We can also set a default value if the property or value does not exist
See the example below:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store