-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathscope.js
More file actions
44 lines (34 loc) · 765 Bytes
/
scope.js
File metadata and controls
44 lines (34 loc) · 765 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
var x = 90;
function hello(){
var x = 100;
console.log(x);
}
hello()
// check value in scope of function first
// check value outside or in global scope
//-----------------------------------------//
function hello(){
var x = 100;
// function level scope
if(true){
x =80;
}
// console.log(x);
// x will be 80 here
}
//----------------------------------//
function hello(){//
console.log(x);
// undefined
// function level scope
// console.log(x);
// x will be 80 here
// hoisting of variables
var x = 70;
}
//------------------------------------//
var x = 90 ;
function hello(){ // i know i have x inside me
console.log(x); // ?? // x === 90
var x = 70; // function also have same variable
}