Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit d1d987c

Browse files
authored
Update LESSONPLAN.md
1 parent 85bac79 commit d1d987c

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

Week2/LESSONPLAN.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,54 @@ Notes:
2424
- Asynchronous helps us do multiple things in parallel
2525

2626

27-
## 3. What callbacks are and how to write your own
27+
## 3. Callbacks
28+
2829
### Explanation
30+
31+
A callback in JavaScript is basically a function(callback) being passed as a parameter to another function which after some point of time would execute the function passed or invoke the callback.
32+
33+
Callbacks were primarily introduced in JavaScript to achieve asynchronous behaviour
34+
(https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced)
2935
### Example
36+
Consider a situation where person A wishes to go out for a movie with a friend person B one evening. Person A finds out the time and place and now needs to share it with B. A picks up the phone and tries to call B. Let's say that B is currently busy with some work and can't answer the phone. Person A has now got two options. One option is to stay on the line until B picks up the phone and then share the movie details. Or A could drop a voicemail and ask B to __callback__ once free.
37+
38+
``` javascript
39+
function doHomework(subject, callback) {
40+
alert(`Starting my ${subject} homework.`);
41+
callback();
42+
}
43+
function alertFinished(){
44+
alert('Finished my homework');
45+
}
46+
doHomework('math', alertFinished);
47+
```
48+
3049
### Exercise
31-
### Essence
32-
Notes:
3350

34-
- Callbacks are a way to introduce asynchronocity
51+
#### 1. What will happen?
52+
#### 2. How to turn the output order around?
53+
``` javascript
54+
function first(){
55+
// Simulate a code delay
56+
setTimeout( function(){
57+
console.log(1);
58+
}, 500 );
59+
}
60+
function second(){
61+
console.log(2);
62+
}
63+
64+
first();
65+
second();
66+
```
3567

3668

69+
### Essence
70+
you can’t just call one function after another and hope they execute in the right order. Callbacks are a way to make sure certain code doesn’t execute until other code has already finished execution.
71+
3772
SECOND HALF (14.00 - 16.00)
3873

39-
## 4. How the event loop works
74+
## 4. Event loops
4075

4176
### Explanation
4277
### Example
@@ -48,7 +83,7 @@ Notes:
4883
- It determines when any given function is executed
4984

5085

51-
## 5. Show 3 commonly used array functions (filter, reduce, map)
86+
## 5. 3 commonly used array functions (filter, reduce, map)
5287
### Explanation
5388
### Example
5489
### Exercise

0 commit comments

Comments
 (0)