Skip to main content

var vs let vs const in Javascript

var, let and const are used to declared variables in Javascript.

VAR

Used to declare variables as global scoped or function scoped. A global scoped variable is accessible anywhere in the code while function scoped can only be used within that function.

LET

Introduced in ES6 and it is block scoped. A block scoped variable is only accessible inside the block it is declared.

CONST

Used to declare variables that maintain their values, the values are defined at the declaration level. These types of variables are also block-scoped like let