Difference Between var, let, and const in JavaScript

This article is created to differentiate between var, let, and const in JavaScript. These three are the keywords, used to declare a variable in JavaScript.

var Vs let Vs const in JS

var let const
declares function-scoped or globally-scoped variable declares block-scoped local variable declares block-scoped variable
can be updated and re-declared can be updated but cannot be re-declared neither can be updated nor be re-declared
can be declared without initializing any value can be declared without initializing any value can not be declared without initializing any value

Note - Accessing a variable declared using var keyword without initialization, returns undefined.

JavaScript Online Test


« Previous Tutorial Next Tutorial »