-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_var_keyword.js
More file actions
31 lines (25 loc) · 877 Bytes
/
02_var_keyword.js
File metadata and controls
31 lines (25 loc) · 877 Bytes
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
// Topic: `var` Keyword (Not Recommended)
// Note:
// -> It can be initialized later.
// -> It can be reassigned.
// -> It can be redeclare in same scope.
// -> It can be redeclare in different scope.
// Note
// Variable declared with var keyword:
// - If it has global scope, it can be accessed inside anywhere.
// - If it has function scope, it can be accessed only inside the function where it is declared.
// - If it has block scope (like if, for, while), it can still be accessed outside the block, Globally and also inside functions.
// Syntax:
// var variableName = value;
// Example:
// Initialized later
var variable;
variable = "value";
// Reassigned
var variable = "value1";
variable = "value2";
// Redeclare
// - As you can see your are using same variable name twice.
// - It will take latest updated value.
var variable = "value1";
var variable = "value2";