- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_type_function.html
More file actions
Latest commit
194 lines (176 loc) · 4.79 KB
/
Copy pathall_type_function.html
File metadata and controls
194 lines (176 loc) · 4.79 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>demo</title>
</head>
<body>
<!--=====Function 1 alert with function======-->
<inputtype="button" onclick="sayHello()" value="Say Hello">
<script>
functionsayHello()
{
alert("Hello there!");
}
</script>
<!--=====Function 2 alert data with function======-->
<inputtype="button" onclick="sayHello('Zara', 7)" value="Say Hello">
<script>
functionsayHello(name,age)
{
alert(name+" is "+age+" years old.");
}
</script>
<!--=====Function 3 print data with var function=====-->
<pid="demo"></p>
<script>
functionmyFunction(a,b){
returna*b;
}
varx=myFunction(4,3);
document.getElementById("demo").innerHTML=x;
</script>
<!--=====Function 4 print value with function======-->
<pid="demo14"></p>
<script>
vara=4;
functionmyFunction(){
document.getElementById("demo14").innerHTML=a*a;
}
</script>
<pid="demo41"></p>
<script>
varx=7;
functionmyFunc2(a){
returna*a;
}
document.getElementById('demo41').innerHTML=myFunc2(5)*x;
</script>
<!--=====Function 5 anonymous / function expression======-->
<pid="demo3"></p>
<script>
varx=function(a,b){returna*b};
document.getElementById("demo3").innerHTML=x(4,3);
</script>
<!--=====Function 6 print data with var function======-->
<pid="demo6"></p>
<script>
functionmyFunction(a,b){
returna*b;
}
varx=myFunction(4,3)*2;
document.getElementById("demo6").innerHTML=x;
</script>
<!--=====Function 7 object function======-->
<pid="demo4"></p>
<script>
varperson={
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function(){
returnthis.firstName+" "+this.lastName;
}
};
document.getElementById("demo4").innerHTML=person.fullName();
</script>
<!--=====Function 8 concatenate function======-->
<inputtype="button" onclick="secondFunction()" value="Call Function">
<script>
functionconcatenate(first,last)
{
varfull;
full=first+last;
returnfull;
}
functionsecondFunction()
{
varresult;
result=concatenate('Zara','Ali');
document.write(result);
}
</script>
<!--=====Function 9 object constructor call function======-->
<pid="demo9"></p>
<script>
varperson={
fullName: function(){
returnthis.firstName+" "+this.lastName;
}
}
varperson1={
firstName:"John",
lastName: "Doe",
}
varperson2={
firstName:"Mary",
lastName: "Doe",
}
varx=person.fullName.call(person1);
document.getElementById("demo9").innerHTML=x;
</script>
<!--=====Function 10 object constructor call function======-->
<pid="demo11"></p>
<script>
varperson={
fullName: function(city,country){
returnthis.firstName+" "+this.lastName+","+city+","+country;
}
}
varperson1={
firstName:"John",
lastName: "Doe",
}
varperson2={
firstName:"Mary",
lastName: "Doe",
}
varx=person.fullName.call(person1,"Oslo","Norway");
document.getElementById("demo11").innerHTML=x;
</script>
<!--=====Function 11 object constructor apply function======-->
<pid="demo12"></p>
<script>
varperson={
fullName: function(city,country){
returnthis.firstName+" "+this.lastName+","+city+","+country;
}
}
varperson1={
firstName:"John",
lastName: "Doe",
}
varx=person.fullName.apply(person1,["Oslo","Norway"]);
document.getElementById("demo12").innerHTML=x;
</script>
<!--=====Function 12 object constructor new function=====-->
<pid="demo2"></p>
<script>
varmyFunction=newFunction("a","b","return a * b");
document.getElementById("demo2").innerHTML=myFunction(4,3);
</script>
<!--=====Function 13 consturctor value new function======-->
<pid="demo8"></p>
<script>
functionmyFunction(arg1,arg2){
this.firstName=arg1;
this.lastName=arg2;
}
varx=newmyFunction("John","Doe")
document.getElementById("demo8").innerHTML=x.firstName;
</script>
<!--=====Function 14 self invoke======-->
<pid="demo">0</p>
<script>
varadd=(function(){
varcounter=0;
returnfunction(){
counter+=1;returncounter;
}
})();
functionmyFunction(){
document.getElementById("demo").innerHTML=add();
}
</script>
</body>
</html>