-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.js
More file actions
51 lines (37 loc) · 869 Bytes
/
callback.js
File metadata and controls
51 lines (37 loc) · 869 Bytes
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
// callback = a function that is passed as an argument
// to another function.
// used to handle asynchronous operations:
// 1. Reading a file
// 2. Network requests
// 3. Interacting with databases
// "Hey, when you're done, call this next."
/*
hello(goodbye);
wait();
leave();
function hello(callback){
console.log("Hello!");
callback();
}
function wait(){
console.log("Wait!");
}
function leave(){
console.log("Leave!");
}
function goodbye(){
console.log("Goodbye!");
}
*/
// sum of two variables using callback
sum(displayPage, 1, 2);
function sum(callback, x, y){
let result = x + y;
callback(result);
}
function displayConsole(result){
console.log(result);
}
function displayPage(result){
document.getElementById("myH1").textContent = result;
}