🎄 Get 20% off from our JavaScript course for the holidays! 🎄
What are the Differences Between var, let, and const?

What are the Differences Between var, let, and const?

Ferenc AlmasiLast updated 2023 April 19 • Read time 1 min read
  • twitter
  • facebook

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:

This is the default: it creates a function scoped variable which can be reassigned or redeclared later on.

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.

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.

var vs let vs const in JavaScript
If you would like to see more Webtips, follow @flowforfrank

50 JavaScript Interview Questions


Did you find this page helpful?
📚 More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access exclusive interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Remove ads to learn without distractions
Become a Pro