Some ES6 features you should know

Naymul Hasan
2 min readNov 3, 2020

Hello good people. I hope you are well. Today I am going to write about some awesome features of ES6.I will discuss about scope,block binding,var,let,const,spread operator etc.

Scope:

If you ever write code in javascript you might hear about scope. So what does actually scope mean?. Scope determines the visibility or accessibility of a variable or other resources in the area of your code

There are two types of scope in javascript they are :

1.Global scope

2.local scope

And local scope also can be classified into two types.

1.function scope

2.Block Scope

Now we are going to see what actually global, local, function scope are.

Global Scope: The global scope means the complete javascript environment. Generally, the global scope is the area outside of a function of your code.

Function scope: The are inside a function is said to be a function scope. Function scope is also said to be block scope.

Block Scope: Generally, the area inside if, for, switch, etc are said to be block scope.

In the above picture, the variable name is in the global scope, and the variable message is in the function scope. The area inside if and else block is called block scope. Of course, function scope is also said to be a block scope.

Now we will learn about the difference between var, const, and let.

Var: By using var we can declare a variable in javascript. Var use function scope means that if you declare var anywhere inside a function you can access it inside the function from anywhere. Let's see an example.

In the above example if we call the function with true then we can see the output 5. See we declare our variable inside a block scope but we can access it from outside of the block. That how var works in javascript.

Let: Let use block scope. We know about block scope. Now let's see an example

In the above example, we see that if we call the function with true then we will get an error. Why? Because we declare the variable inside if{} block and then we want to access it outside of the block. That's how let works. You can also reinitialize the variable declared with let.

Const : Const works like let but in the case of let we can reinitialize the variable but we can’t do it with const.

--

--

Naymul Hasan

I am Naymul Hasan Fahim a javascript enthusiast.I love to write code.My core skill is based on javascript