Skip to content

Commit 8c2591b

Browse files
authored
Add files via upload
add note
1 parent b0924d0 commit 8c2591b

5 files changed

+114
-0
lines changed

Anonymous function in javascript.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Anonymous Function</title>
7+
</head>
8+
<body>
9+
<script>
10+
// anonymous Function
11+
var a = function test(){
12+
document.write("hello");
13+
};
14+
a();
15+
</script>
16+
17+
</body>
18+
</html>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Function Expression</title>
7+
</head>
8+
<body>
9+
<script>
10+
// When we create a function and assign it to a variable,know as function expression
11+
var a = function show(){
12+
document.write("Hello");
13+
}
14+
a();
15+
</script>
16+
17+
</body>
18+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Passing Anonymous Function Argument</title>
7+
</head>
8+
<body>
9+
<script>
10+
// anonymous function allows the creation of function which have no specified name.
11+
function dis(mycode){
12+
return mycode();
13+
14+
}
15+
document.write(dis(function(){
16+
return "passing anonymous function argument Example";
17+
}));
18+
</script>
19+
</body>
20+
</html>

Returning Anonymous Function .html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Returning Anonymous Function</title>
7+
</head>
8+
<body>
9+
<script>
10+
function show(x){
11+
return function(y){
12+
return x+y;
13+
};
14+
}
15+
xf = show(10);
16+
document.write(xf(50));
17+
</script>
18+
</body>
19+
</html>

closure in javascript.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Closure</title>
7+
</head>
8+
<body>
9+
<script>
10+
// A closure is a fucntion having access to the parent scope. it preserve the data form outside.
11+
// A closure is an inner fucntion that has access to the outer (enclosing) function's variables.
12+
// for every closure we have three scopes.
13+
// 1. local scope (own scope) 2. outer function scope 3. Global scope
14+
15+
// example
16+
var a = 10;
17+
function x(){
18+
var b = 60;
19+
document.write(b +"<br>");
20+
document.write(a +"<br>");
21+
22+
}
23+
x();
24+
// example 2
25+
function test(){
26+
var c = "local variable outer function";
27+
document.write(c +"<br>");
28+
function inner(){
29+
var d = "local variable inner fucntion";
30+
document.write(d + "<br>");
31+
}
32+
inner();
33+
}
34+
35+
test();
36+
37+
</script>
38+
</body>
39+
</html>

0 commit comments

Comments
 (0)