Some important concept about Javascript ES6

All you know that ES6 ( ECMAScript ) is the second major version of JavaScript. It was released in 2015. Now I wanna discuss some important concepts about ES6.

JavaScript Hoisting

In JavaScript, a variable can be used before it’s declared. If we declare a variable with the var keyword it was hoisted to the top and var is the global scope. Hoisting is JavaScript default behavior it’s hoisted all variables to the top.

let and const keyword

let and const are different from var. We can’t use the let variable before it declares.

when we access the k variable before it declares there is an error occurred. It is the same with the const keyword. we can't access a variable before it declares.

We can see the result is the same.


Variable declare with var key work has no block scope. We can easily access var value into block scope.

As we can see. we easily access x into a block {} scope. But variable keywords with let and const have block scope. we can’t access a variable from block scope which is declared by let and const key word. In the picture below we can see that when we try to access the variable value which is declared with the let key word then an error occur which is Reference Error: x is not defined. Cause it has a block scope so we can’t access its value from outside of the block scope.

It is the same as the const keyword we can’t access its value from outside of the block scope.

Default parameters

In the javascript function, we can set the default parameters value. When function invoked then if its have no the parameters value then default parameters prevent the error of undefined.

In the above example, we can see that when we invoked the sum function with two parameters then it work perfectly, and also when we pass only one parameter its also work fine cause we set a default parameter value. But If don’t set the default parameters value what’s will happen? Let's see…

Its return value is NaN. Cause every function parameter's default value is undefined. So when we invoked the function with one parameter it failed to sum and then return NaN. So, to prevent this type of situation we can use the default parameters value.

Arrow function

Its introduce in ES6. If you wanna use shorter function syntax then you can use the arrow function.

If you think it’s complicated then don’t worry if the function has one statement then you don’t need to write a return.

The output is the same. If you have multiple statements then you should use curly braces and return. And also If you have only one parameter in the arrow function you don’t need to write it within parenthesis.

So Finally, I hope that these some concepts help you to gain little knowledge about javaScript ES6. keep learning best wishes to you.

Happy Coding :)

Front-End Developer || MERN Stack Developer

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