File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ */
You can’t perform that action at this time.
0 commit comments