This Angular tutorial helps you get started with Angular quickly and effectively through many practical examples.

JavaScript Var vs Let vs Const Keywords


In this tutorial post we are going to discuss the following keywords var ,let and const. We will see the difference between these keywords.

1. JavaScript Var Variable

The var keyword declares a function-scoped or global variable, optionally initializing it to a value. Function-scoped means that the variable is only available within the function it was declared in. Global variables are available throughout your entire code.

2. JavaScript let Variable

The let keyword declares a block-scoped local variable, optionally initializing it to a value. Block-scoped means that the variable is only available within the block it was declared in, which is usually denoted by curly braces {}.

3. JavaScript const Variable

The const keyword declares a block-scoped, immutable constant variable, i.e. a variable that can’t be reassigned. Constants are also called immutable variables, but that’s a bit of a misnomer since they are actually variables – just ones that can’t be reassigned.

Var vs Let vs Const Keyword

SNo. Var Keyword Let Keyword Const Keyword
1 The Var keyword introduce in JavaScript before the advent of ES6. The Let keyword introduce in JavaScript in the advent of ES6 The Const keyword introduce in JavaScript in the advent of ES6
2 The Var declarations can be globally or function scoped. The Let keyword scope is limited to block scope The Const keyword scope is limited to block scope
3 The Var can be re-declared The Let can not re-declared The Const cannot be re-declared into the scope.
4 Var can be updated The Let can be updated The Const can not be updated
5 Hosting of Var means declarations of variales and function should be before execution of code. It is initialized as undefined Hosting of Var means declarations of variales and function should be before execution of code. It is left as uninitialized Hosting of Var means declarations of variales and function should be before execution of code. It is left as uninitialized

Prev Next