-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedFunctions-pratice.html
More file actions
83 lines (67 loc) · 2.28 KB
/
AdvancedFunctions-pratice.html
File metadata and controls
83 lines (67 loc) · 2.28 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Advance Functions</title>
</head>
<body>
<button>button</button>
<script>
// Function are values.
let a = function() {
console.log('Hello');
}
console.log(a());
const object = {
name : 'Gowtham',
fun : function() {
console.log("HI");
}
};
console.log(object.fun());
function function1(param) {
param();
}
function1(function greting() { //call back function.
console.log("Hello");
});
setTimeout(() => {console.log('HI');}, 2000);
// setInterval(() => {console.log('HI');},2000);
// forEach Loop
const arr = [1,2,3,4,5];
arr.forEach((value, index) => {console.log(value);});
// continue use as return in forEach Loop
// break is not used in forEach Loop.
arr.forEach((value) => {
if(value === 3)
return;
console.log(value);
});
// Arrow Functions.
const arrofunction = () => {console.log('hello');};
arrofunction();
// passing a parameter.
// for one parameter there is no need of brackets.
const oneparam = param => {return param + 5;};
console.log(oneparam(5));
//one Line Arro function
//const oneLine = () => {return 2 + 3;};
const oneLine = () => 2 + 3;
console.log(oneLine());
console.log(typeof oneparam);
console.log(typeof arr);
console.log(typeof {name : 'Gowtham'});
console.log(Array.isArray(arr));
console.log(Array.isArray(oneparam));
console.log(Array.isArray({name : 'Gowtham'}));
// EventListener
const button = document.querySelector('button');
const buttonFunction = () => {console.log('click');};
// adding EventListener to button.
button.addEventListener('click', buttonFunction);
// we can also add multiple events to one button using EventListener.
button.addEventListener('click',() => {console.log('click2');});
// we can also remove event listiner.
button.removeEventListener('click', buttonFunction);
</script>
</body>
</html>