
What are the Differences Between var, let, and const?
When no keyword is used, the variable will be assigned to the global object which is the window
if we are in a browser. There are three keywords in JavaScript you can use for variable declarations. These are:
var
This is the default: it creates a function scoped variable which can be reassigned or redeclared later on.
let
This was introduced in ES6 and it is the preferred way over using var
. It creates a block-scoped variable which can be reassigned but can’t be redeclared.
const
It was introduced in ES6 along with let
. It also creates a block-scoped variable but this can’t be reassigned nor redeclared. const
should be used when you don’t want to reassign a value later on.
It’s also good to mention that all declarations will be hoisted to the top of their scope.
var
should be avoided if can, use let
or const
instead.

Resources:
Access exclusive interactive lessons
Unlimited access to hundreds of tutorials
Remove ads to learn without distractions