-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_variable.js
More file actions
35 lines (28 loc) · 1.47 KB
/
01_variable.js
File metadata and controls
35 lines (28 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Variable
// What
// - Variables in JavaScript are like containers where you can store information. This information can be numbers, text, lists, or even more complex data.
// Why
// - Variables are used to keep track of data that we want to use or change in our programs. They help us store values temporarily and reuse them later in our code.
// Note
// - To create variable you can use var, let and const keyword.
// - `var` keyword has been deprecated so it's not recommended to use. Only use `let` and `const`.
// - The fact that whenever we declare a variable and assign a value to it, it’s not the variable that holds the value but rather the variable just holds an address in the memory where the initialized value is stored.
// - For example:
let age = 21;
// - when we use age, it gets replaced with 21, but that does not mean that age contains 21, rather what it means is that the variable age contains the address of the memory location where 21 is stored.
// Syntax
// Single variable
var variable = 1; // Not Recommended
let variable1 = 2;
const variable2 = 3;
// Multiple variable with same value
// - First declare and use comma to separate the variables.
// - Second initialize and use equal sign instead of comma.
let variable3, variable4, variable5;
variable3 = variable4 = variable5 = 1;
// Multiple variable with different value
// - Declaring and initializing at the same time.
// - Use comma to separate the variables.
let variable6 = 1,
variable7 = 2,
variable8 = 3;