-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalScope.js
More file actions
63 lines (38 loc) · 934 Bytes
/
GlobalScope.js
File metadata and controls
63 lines (38 loc) · 934 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Global Scope
var myGlobal = 10;
function fun1() {
oopsGlobal = 5;
}
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += "oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
fun1();
fun2();
// Local Scope & functions
function myLocalScope() {
var myVar = 5;
console.log(myVar);
}
myLocalScope();
console.log(myVar); // This is not going to work because it's outside of the local scope
// Local vs Global
//Global Variable
var seasonUtah = Sprint;
function seasonGuadalajara() {
return seasonUtah;
}
console.log(seasonGuadalajara); // It will return Sprint
//Local Variable
var seasonUtah = Sprint;
function seasonGuadalajara() {
var seasonUtah = "Summer"
return seasonUtah;
}
console.log(seasonGuadalajara()); //it will return Summer