Variables
Variables are Containers for Storing Data.
JavaScript Variables can be declared in 4 ways: 1. Automatically 2. Using var 3. Using let 4. Using const
//Automatically
accountCity = "Jaipur"
//Using var
var accountPassword = "12345"
//Using let
let accountEmail = "hitesh@google.com"
let accountState;
//Using const
const accountId = 144553
accountEmail = "hc@hc.com"
accountPassword = "21212121"
accountCity = "Bengaluru"
console.table([accountId, accountEmail, accountPassword, accountCity])
Console Output:
(index) | Values |
---|---|
0 | 144553 |
1 | 'hc@hc.com' |
2 | '21212121' |
3 | 'Bengaluru' |
-> accountId = 2 // not allowed as const values can't be changed -> Prefer not to use var because of issue in block scope and functional scope.
