DEV Community

Sujith V S
Sujith V S

Posted on • Updated on

let & const | JavaScript ES6.

let and const are used to create variable in js.

let is same as var in old js. let allows us to create variables where its values can be changed.
eg:-

let myName = "Sujith";
myName = "Ajith";
Enter fullscreen mode Exit fullscreen mode

The above code would give the result as Ajith because we have reassigned a new value to the variable myName.

const is used to create a variable where its value cannot be changed or reassigned after initial assignment.

const myName = "Sujith";
myName = "Ajith";
Enter fullscreen mode Exit fullscreen mode

The above code would give us the following error.
TypeError: Assignment to constant variable.

Top comments (0)