GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — JavaScript Variables - GeeksforGeeks JavaScript VariablesLast Updated : 15 Jun, 2026 Variables in JavaScript are used to store data values. They can be declared in different ways depending on how the value should behave.
Declaring Variables in JavaScript
1. var keywordvar is a keyword in JavaScript used to declare variables and it is Function-scoped and hoisted, allowing redeclaration but can lead to unexpected bugs.
2. let keywordlet is a keyword in JavaScript used to declare variables and it is Block-scoped and not hoisted to the top, suitable for mutable variables
3. const keywordconst is a keyword in JavaScript used to declare variables and it is Block-scoped, immutable bindings that can't be reassigned, though objects can still be mutated.
Rules for Naming VariablesWhen naming variables in JavaScript, follow these rules
Interesting Facts about Variables in JavaScript1. let or const are preferred over var: Initially, all the variables in JavaScript were written using the var keyword but in ES6 the keywords let and const were introduced. The main issue with var is, scoping.
2. var is function scoped: Can be accessed outside block if within the function.
3. let and const are block scoped : Cannot be accessed outside block even if inside the same function
4. var can be redeclared in the same scope, but let and const cannot be
5. We can change elements of array or objects even if declared as const.
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |