The simple difference between var, let and const in Javascript

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 uninstall Cocoapods from the Mac OS? #4 How to Use SQL MAX() Function with Dates? #5 How to add Read More Read Less Button using JavaScript? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Apr 7 Solution for “Yarn build: Failed because of a stylelint error” Apr 7 Make sure your links have descriptive text Apr 7 How to add Laravel to WordPress using Sage theme (and install Tailwind CSS)? Apr 2 How to create a sidebar using pure CSS? Apr 1 How to switch dark and light themes using pure CSS? Apr 1 How to calculate elapsed time in JavaScript?

You might also like these

How to add a Bar Chart in Angular App?AngularThe Differences Between HAVING Clause and WHERE Clause in SQLSQL/MySQLLearn to create profile card using HTML and CSSCSSHow to apply style only to first child and/or only to children other than the first child?CSSHow to Remove PHP File Extensions From Your Website URLs?PHP12 URLSearchParams methods in JavaScriptJavaScriptNumber Properties in JavaScriptJavaScript5 Ways to Loop Through JavaScript ArraysJavaScriptKilling A Project Part 3: How can an organization ensure that a doomed project is killed as early as possible?MiscSolution for the error Commit failed – exit code 1 received in Desktop GithubMiscThe fundamental difference between HAVING and WHERE clauses in PostgresPostgresWhat’s new in WordPress 5.5?WordPress