Difference between var, let and const keyword in JavaScript
In JavaScript, We can declare a variable using below keywords: var let const Below are the difference between these keywords: Scope: The scope of the "var" keyword is the global scope. Means variables defined outside the function can be accessed globally. <script> var a = 20; function fun() { if (true) { var b = 30 // declared in "if" block but can be accessible outside of this "if" block. } console.log(b); console.log(a); } fun(); </script> Output: 30 20 The scope of a "let" variable is only block scoped. It can’t be accessible outside the particular block. Have a look at below example: <script> let a = 20; function fun() { if (true) { ...