YogeshChauhan . com

The simple difference between var, let and const in Javascript

in JavaScript on February 22, 2020


A var variable can be re-declared and updated. var is “function scoped”.

The scope of a variable defined with “var” is limited to that “function”. If it is defined outside any function, then the scope of the variable is global.


A let variable be be updated but not re-declared. “let” is “block scoped”.

The scope of a variable defined with “let” is limited to the “block” which is defined by curly braces -> {}


As per the name suggests, const variables cannot be updated. 

We can not re-assign value to the variable but it CAN be mutated.

Same as "Let", The scope of a variable defined with “let” is limited to the “block” which is defined by curly braces -> {


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to create two segues with two UIButtons on a single page (Swift 5.0)?Swiftfirst-of-type and last-of-type selectors in CSSCSSLearn to create profile card using HTML and CSSCSSWhat’s a Strict mode in JavaScript?JavaScriptHow to check if the element exists using JavaScript and jQuery?JavaScriptHow to obfuscate JavaScript code to hide it from View Source?JavaScriptHere’s what we can do with PHP date() functionPHPKilling A Project Part 4: What Would Be Your Top 3 Priorities For Planning The Cancellation?MiscRevisiting variable scope in JavaScriptJavaScriptClasses in JavaScript: The BasicsJavaScriptWhat are Null Sessions?MiscHow to get Current Hour, Minute and Second in JavaScript?JavaScript