8000 global scope · last-endcode/JavaScript-Basics@96a839f · GitHub
[go: up one dir, main page]

Skip to content

Commit 96a839f

Browse files
committed
global scope
1 parent c3186fc commit 96a839f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

30_globalscope.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Global scope vs Local variable
2+
// any variable outside code block{}
3+
// is said to be in GLOBAL scope
4+
// can be access anywhere in the program
5+
6+
let name = 'john doe';
7+
8+
function localFunction() {
9+
console.log(`${name} in function`);
10+
name = 'peter function';
11+
//inner
12+
function inner() {
13+
console.log(`here inside ${name}`);
14+
name = 'use inner function';
15+
}
16+
// invoking innner
17+
inner();
18+
}
19+
20+
console.log(`${name} in outside function`); //john doe
21+
localFunction(); //john doe
22+
23+
if (true) {
24+
console.log(name + 'in condition if');
25+
name = 'hello change again in if';
26+
}
27+
28+
console.log(name);
29+
30+
/* ooutput
31+
john doe
32+
john doe in function
33+
here inside peter function
34+
use inner function in condition if
35+
hello change again in if
36+
*/

0 commit comments

Comments
 (0)
0