DEV Community

Divya Divya
Divya Divya

Posted on

What difference between Var,Let and Const?

Var: Var is a function-scoped and can be redeclared and reassigned.


var a=10;
a=20;
console.log(b);

Output:
20
Enter fullscreen mode Exit fullscreen mode

Let: Var is a block-scoped and can be reassigned but not redeclared.It's used for variables that change.



let a=30;
a=10;
console.log(b);

Output:
10
Enter fullscreen mode Exit fullscreen mode

Const:Const is a block-scpoed cannot be reassigned or redeclared.It's used for fixed values.


const a=110;
a=80;
console.log(b);

Output:
110
Enter fullscreen mode Exit fullscreen mode

Top comments (0)