Nearby lessons
4 of 40๐ก JavaScript Variables
๐ What are JavaScript Variables?
๐ JavaScript variables are used to store data values. You can declare them in different ways:
- ๐น Automatically
- ๐น Using
var - ๐น Using
let - ๐น Using
const
๐ var Keyword
- ๐
The
varkeyword was used in all JavaScript code from 1995 to 2015. - โจ The
letandconstkeywords were added to JavaScript in 2015. - โ ๏ธ Use
varonly for older browsers.
Code Example
PREVIEW READY
๐ let Keyword
- โ Variables defined with
letcannot be redeclared. - โ Must be declared before use.
- ๐ฆ Has block scope.
Code Example
PREVIEW READY
๐ const Keyword
- โ Variables with
constcannot be redeclared or reassigned. - ๐ฆ Has block scope.
Code Example
PREVIEW READY
๐ฆ JavaScript Variable Keywords
| Attribute | Description |
|---|---|
var | โ Can be redeclared and updated. Has function or global scope. Use in legacy code. |
let | โ ๏ธ Cannot be redeclared, but can be updated. Has block scope. |
const | ๐ Cannot be redeclared or updated. Must be initialized. Has block scope. |
๐ง Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!JS - Data Types