-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay24Variblescope.html
37 lines (33 loc) · 1.05 KB
/
Day24Variblescope.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Day24</title>
</head>
<body>
<script>
// closure in javascript
//funtion which has reference to its outer funtion is called closure in javascript
function counter(){
let count=0;//it is not possible to change this count directly
return function(){
return count++;
}
}
let count =counter();//this funtion runs only one but inner funtion remembers the count value
console.log(count());//0
console.log(count());//1... goes on
function person(){
let firstname="ponmani";// we cant directly change the name
let lastname="venkatesan";
function name(){
return (firstname+" "+lastname);
}
return name;
}
let getname=person();
console.log(getname());// ponmani venkatesan
</script>
</body>
</html>