Yogesh Chauhan's Blog

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 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Effects in ReactReactHow to overwrite file contents with new content in PHP?PHPObject destructuring in JavaScript: Unpacking fields from objects passed as function parameterJavaScriptALTER DATABASE in PostgreSQLPostgresGive buttons accessible namesUI/UXRecursion in JavaScriptJavaScriptThe fundamental difference between HAVING and WHERE clauses in PostgresPostgresHow to render lists inside a component in React?ReactHow to Skip or Exclude a Specific URL or File From .htaccess Rewrite Rule?PHPAngular: Templates, directives, data binding, Services and dependency injectionAngularTackle Accessibility in React with JSXReactPHP Variables ScopePHP