ES6 For Beginners : Using const keyword Declaration

The const keyword as the name suggests is a great way to create constants in JavaScript with ES6. As we will see in the code snippets below the const keyword will give developers another tool to write more meaningful code easily.

Let’s dive right into the code, I will use more or less the same code that I used in the post about the let keyword.

1

2

3

4

5

6

constpi=3.14;

if(1==1){

pi="some other value";

}

alert(pi);

Here we are declaring the variable pi as a constant with the const keyword, inside the if condition we are changing the value of the constant pi this will give us the following error.