-
Notifications
You must be signed in to change notification settings - Fork 0
/
day28.js
68 lines (33 loc) · 1.02 KB
/
day28.js
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
// closure & lexical scope
//lexical
function init(){
let name ="karan singh";
console.log("outer func");
function display(){
let inner1="inner func"
console.log(name); //acess of the varible inside the inner function
}
function display1(){
let inner2="inner func"
console.log(name); //acess of the varible inside the inner function
// console.log(inner1); //cannot access among the inner funcs
}
display()
display1()
}
init()
// closure
// let orange=document.getElementById("orange").onclick=(()=>{
// document.body.style.backgroundColor="orange"
// })
// let green=document.getElementById("green").onclick=(()=>{
// document.body.style.backgroundColor="green"
// })
function clickhandler(color){
// document.body.style.backgroundColor=`${color}`
return function(){
document.body.style.backgroundColor=`${color}`
}
}
document.getElementById("orange").onclick=clickhandler("orange")
document.getElementById("green").onclick=clickhandler("green")