Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff329e5

Browse files
author
Noer Paanakker
committed
added sync vs async content, not finished
1 parent c33de8e commit ff329e5

File tree

8 files changed

+94
-114
lines changed

8 files changed

+94
-114
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
If you were to ask a random person on the street the question "What is a browser?", you'll most likely get a variety of (incorrect) answers. For proof, check [this](https://www.youtube.com/watch?v=o4MwTvtyrUQ) out.
1010

11-
You might be one of those people right now, but after this module no more. In **JavaScript2**
11+
You might be one of those people right now, but after this module no more. In **JavaScript2** you'll learn all about how to use JavaScript within the browser.
1212

1313
## Learning goals
1414

@@ -35,8 +35,8 @@ If you have any questions or if something is not entirely clear ¯\\\_(ツ)\_/¯
3535
| Week | Topic | Reading Materials | Homework | Lesson Plan |
3636
| ---- | --------------------------------------------------- | ------------------------------ | ------------------------------- | -------------------------------------- |
3737
| 1. | Document-Object Model (DOM), DOM manipulation | [Reading W1](/Week1/README.md) | [Homework W1](/Week1/MAKEME.md) | [Lesson Plan W1](/Week1/LESSONPLAN.md) |
38-
| 2. | Developer tools, Web Storage, Event Loop, Callbacks | [Reading W2](/Week2/README.md) | [Homework W2](/Week2/MAKEME.md) | [Lesson Plan W2](/Week1/LESSONPLAN.md) |
39-
| 3. | SPA vs. MPA, Scope, Closures | [Reading W3](/Week3/README.md) | [Homework W3](/Week3/MAKEME.md) | [Lesson Plan W3](/Week1/LESSONPLAN.md) |
38+
| 2. | Synchronous vs. asynchronous, Event Loop, Callbacks | [Reading W2](/Week2/README.md) | [Homework W2](/Week2/MAKEME.md) | [Lesson Plan W2](/Week1/LESSONPLAN.md) |
39+
| 3. | Scope, Hoisting, Closures | [Reading W3](/Week3/README.md) | [Homework W3](/Week3/MAKEME.md) | [Lesson Plan W3](/Week1/LESSONPLAN.md) |
4040

4141
## Test
4242

Week1/MAKEME.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
## **1. Practice the concepts**
1111

12+
- [Making webpages interactive](https://www.khanacademy.org/computing/computer-programming/html-css-js)
13+
1214
## **2. JavaScript exercises**
1315

1416
### 1. The book list
@@ -129,9 +131,9 @@ Start with this webpage, which has a single img tag of an animated GIF of a cat
129131

130132
## **SUBMIT YOUR HOMEWORK!**
131133

132-
After you've finished your todo list it's time to show us what you got! Starting from this week you'll be submitting all your homework through GitHub. What you'll be doing is upload all your files to a forked repository (a copy from the original, which in this case is the [JavaScript1](https://www.github.com/HackYourFuture/JavaScript1) repository) using GIT.
134+
After you've finished your todo list it's time to show us what you got! Upload all your files to a forked repository (a copy from the original, which in this case is the [JavaScript2](https://www.github.com/HackYourFuture/JavaScript2) repository) using GIT. Then make a pull request to the original.
133135

134-
Take a look at the following [guide](../hand-in-homework-guide.md) to see how it's done.
136+
If you need a refresher, take a look at the following [guide](../hand-in-homework-guide.md) to see how it's done.§
135137

136138
The homework that needs to be submitted is the following:
137139

Week1/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ These are the topics for week 1:
1717
- Browser events
1818
- Event listeners and handlers
1919

20-
[DOM Crash Course](https://www.youtube.com/playlist?list=PLillGF-RfqbYE6Ik_EuXA2iZFcE082B3s)
21-
2220
## 1. What is a web browser?
2321

2422
A web browser is software that allows you to access websites.
@@ -84,6 +82,7 @@ JavaScript is made accessible to the DOM by embedding it into an HTML file. You
8482

8583
- [What exactly is the DOM](https://bitsofco.de/what-exactly-is-the-dom/)
8684
- [JavaScript and the browser](https://eloquentjavascript.net/13_browser.html)
85+
- [JavaScript DOM Crash Course - Part 1](https://www.youtube.com/watch?v=0ik6X4DJKCc)
8786

8887
### The Critical Rendering Path
8988

Week2/MAKEME.md

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## **2. JavaScript exercises**
1313

14-
# Step 1: More map, filter and `=>`
14+
Step 1: More map, filter and
1515

1616
_Deadline Wednesday_
1717

@@ -103,70 +103,6 @@ Follow these steps. Each step should build on the result of the previous step.
103103

104104
## **4. PROJECT:**
105105

106-
#
107-
108-
## Step 2: Testing your homework
109-
110-
We have provided _unit tests_ in this repo that allow you to verify that your homework produces the expected results.
111-
112-
> **Unit test**: A _unit test_ is a piece of code (usually a function) that invokes another piece of code and checks the correctness of some assumptions afterwards. If the assumptions turn out to be wrong, the unit test has failed. A 'unit' is a method or function.
113-
>
114-
> Adapted from: Roy Osherove (1.09), The art of Unit Testing. Greenwich, CT: Manning.
115-
116-
At this point it is not important to understand how unit tests work. The only thing you need to know now is how to run the tests and how to determine whether your homework produces the correct results.
117-
118-
#### Run the tests
119-
120-
You can test your week 2 homework by typing this command in the terminal window:
121-
122-
```
123-
npm run test-week2
124-
```
125-
126-
You will see some output appearing in the console while the tests run. If all is well (no errors), the last couple of lines will look like this:
127-
128-
```
129-
Test Suites: 2 passed, 2 total
130-
Tests: 2 passed, 2 total
131-
Snapshots: 0 total
132-
Time: 1.849s
133-
Ran all test suites matching /Week2\//i.
134-
```
135-
136-
In case of unexpected results, say from _Maartjes work_ assignment, you might see something like this (you may need to scroll up a bit):
137-
138-
```
139-
Test Suites: 1 failed, 1 passed, 2 total
140-
Tests: 1 failed, 1 passed, 2 total
141-
Snapshots: 0 total
142-
Time: 1.255s
143-
Ran all test suites matching /Week2\//i.
144-
```
145-
146-
If that's the case, try and fix the error. When done, run the tests again: `npm run test-week2`
147-
148-
Repeat the previous step until all (= 2 in this case) tests pass.
149-
150-
## Step 3: ROVER
151-
152-
Finish up to chapter 7: JSON on [roverjs.com](http://roverjs.com/)!
153-
154-
## Step 4: **Some freeCodeCamp challenges:**
155-
156-
_Deadline Saturday_
157-
158-
1. [Comparisons with the Logical And Operator](https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator)
159-
160-
2. [Record Collection](https://www.freecodecamp.com/challenges/record-collection)
161-
162-
3. [Use the map Method to Extract Data from an Array](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array)
163-
164-
## Step 5: Read before next lecture
165-
166-
_Deadline Sunday morning_
167-
168-
Go trough the reading material in the [README.md](/Week3/README.md) to prepare for your next class
169-
170106
## **SUBMIT YOUR HOMEWORK!**
171107

172108
After you've finished your todo list it's time to show us what you got! Starting from this week you'll be submitting all your homework through GitHub. What you'll be doing is upload all your files to a forked repository (a copy from the original, which in this case is the [JavaScript1](https://www.github.com/HackYourFuture/JavaScript1) repository) using GIT.
@@ -176,5 +112,6 @@ Take a look at the following [guide](../hand-in-homework-guide.md) to see how it
176112
The homework that needs to be submitted is the following:
177113

178114
1. JavaScript exercises
115+
2. PROJECT:
179116

180117
_Deadline Saturday 23.59 CET_

Week2/README.md

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,96 @@
1-
# Reading Material JavaScript2 Week 3
1+
# Reading Material JavaScript2 Week 2
22

33
## Agenda
44

5-
These are the topics for week 3:
5+
These are the topics for week 2:
66

7-
1. Callbacks
8-
2. Event Loop
9-
3. Developer Tools
10-
4. Web Storage
7+
1. Synchronous vs. asynchronous
8+
- Synchronous
9+
- Asynchronous
10+
2. Callbacks
11+
3. Event Loop
1112

12-
## 1. Callbacks
13+
## 1. Synchronous vs. asynchronous
1314

14-
## 2. Event Loop
15+
### Synchronous
1516

16-
How does the browser know what to do first? This is where the Event Loop comes in.
17+
In the previous module you've learned about **control flow**. In short: it's the order in which the computer executes statements in a script. In JavaScript this goes from left to right, top to bottom.
1718

18-
For further study, check out the following resources
19+
Let's look at code execution from another angle. The program that executes your code can do it in two basic ways: synchronous or asynchronous. Whenever code blocks are executed line after line (from top to bottom) we call this **synchronous execution**.
1920

20-
- [What the heck is an event loop?](https://www.youtube.com/watch?v=8aGhZQkoFbQ)
21-
- [JavaScript Event Loop](https://www.youtube.com/watch?v=XzXIMZMN9k4)
21+
Imagine the following scenario:
2222

23-
## 3. Developer Tools
23+
> Noer wants to have breakfast but he doesn't have any food at home. He decides he want to eat oatmeal. The ingredients (oats and milk) can be bought at the supermarket. How to do this? First Noer takes a shower. Then he puts on some clothes. Then some shoes. Then he opens the door and goes outside. Then he jumps on the bike and goes to the closest supermarket. After looking for some time he finds the ingredients. Then Noer buys the ingredients. Then he jump back on the bike and go home. Then he mixes the ingredients and makes oatmeal. Then Noer eats and feels amazing!
2424
25-
- [Google Chrome Developer Tools Crash Course](https://www.youtube.com/watch?v=8aGhZQkoFbQ)
25+
In this example, each action could only happen after the previous has been completed. Noer can't put on his shoes and then take a shower. Or, he can't eat oatmeal before he has bought the ingredients.
2626

27-
## Finished?
27+
As you can see, each action is executed in a **synchronous** manner. This is to say: in a logical order sequentially and only one action at a time.
2828

29-
Are you finished with going through the materials? High five! If you feel ready to get practical, click [here](./MAKEME.md).
29+
This is also how JavaScript by default operates. Only one operation can happen at a time. If something else wants to start, it has to wait until the current action has finished.
30+
31+
### Asynchronous
32+
33+
Sometimes we want to do multiple things, without them being dependent on each other. Consider the following analogy:
34+
35+
> Wouter is feeling hungry so he decides to go to a restaurant. He arrives there and gets into the line to order food. After ordering he takes a seat and, while he waits, reads a book. Occassionally he looks around and sees different things happening: new people enter the restaurant, some people get their food served and others are just talking. After a short while Wouter's food arrives and it's time to dig in!
36+
37+
In this example Wouter reads a book, but that doesn't affect his meal from being prepared. Other
38+
39+
Take a look at the following diagram:
40+
41+
![Sync vs. Async](../assets/javascript-sync-vs-async.png)
42+
43+
```js
44+
function first() {
45+
console.log('this finishes first');
46+
}
47+
function second() {
48+
console.log('this finishes second');
49+
}
3050

31-
## Here are resources that we like you to read as a preparation for the coming lecture.
51+
first();
52+
second();
53+
```
3254

33-
### JSON
55+
In this example, only after `first()` has been executed will `second()` be executed. Only one thing happens at a time, and the next thing will ONLY happen after the previous thing has finished. This synchronous execution happens predictably and sequentially, without exception.
3456

35-
- [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) (MDN)
57+
On the other hand we have
3658

37-
### Map and Filter
59+
Executing each block of code (whether it's a line or a loop/function/etc.) after each other is called
3860

39-
- :dizzy: [Fun fun functional](https://www.youtube.com/playlist?list=PL0zVEGEvSaeEd9hlmCXrk5yUyqUag-n84) :dizzy: Check the first 3-4 videos.
61+
This method of execution can have undesirable ramifications. Suppose a function is called to start a time consuming process. What if you want to stop the lengthy process? With synchronous execution, your program is “stuck,” waiting for the process to end, with no way out.
4062

41-
### Code conventions
63+
Asynchronous execution avoids this bottleneck. You are essentially saying, “I know this function call is going to take a great deal of time, but my program doesn’t want to wait around while it executes.”
4264

43-
- Code conventions: http://crockford.com/javascript/code.html
65+
## 2. Callbacks
4466

45-
### Array cardio
67+
Imagine the following situation:
4668

47-
- Wes Bos' awesome free tutorials. Just make a free account and do Array Cardio #1 [here](https://javascript30.com/)
69+
> It's 15.00 and you studying at home for an exam on the next day. Suddenly, your phone rings. You pick up and find it's your best friend! They ask if you'd like to hang out later. What do you do? On the one hand, you'd love to hang out have fun. On the other hand, you really should study some more. You don't know so tell your friend that you're going to call back later with your answer. You end the conversation and go back to studying. Maybe you take a short break and
4870
49-
### From _Eloquent JavaScript_
71+
By default JavaScript works **synchronously**, as we've learned in the previous section.
5072

51-
- Objects continued: http://eloquentjavascript.net/06_object.html
73+
This is why callbacks are important: it allows us to introduce asynchronicity in the control flow of a program.
5274

53-
## Recommended readings
75+
A concrete example for why this might be useful is when you want to
5476

55-
This chapter from _Eloquent JavaScript_ gives in-depth explanations of the topics that will be discussed during the lecture. Highly recommended (if time permits).
77+
Study the following resources to learn more about the importance of callbacks:
5678

57-
- Chapter 3 - [Functions](http://eloquentjavascript.net/03_functions.html)
58-
- Chapter 5 - [Higher-Order Functions](http://eloquentjavascript.net/05_higher_order.html)
79+
- [Asynchronous JavaScript JavaScript](https://www.youtube.com/watch?v=YxWMxJONp7E)
80+
- [Understanding JavaScript Callbacks](https://www.youtube.com/watch?v=Nau-iEEgEoM)
81+
- [Callback Functions](https://www.youtube.com/watch?v=QRq2zMHlBz4)
5982

60-
_Please go through the material and come to class prepared!_
83+
## 3. Event Loop
84+
85+
If a webpage contains JavaScript, then the browser knows it has to execute these instructions at some point. But how does the browser know what to do first? This is where the `Event Loop` comes in.
86+
87+
In layman's terms, the `Event Loop` is
88+
89+
For further study, check out the following resources
90+
91+
- [What the heck is an event loop?](https://www.youtube.com/watch?v=8aGhZQkoFbQ)
92+
- [JavaScript Event Loop](https://www.youtube.com/watch?v=XzXIMZMN9k4)
93+
94+
## Finished?
95+
96+
Are you finished with going through the materials? High five! If you feel ready to get practical, click [here](./MAKEME.md).

Week3/README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
# Reading Material JavaScript2 Week 2
1+
# Reading Material JavaScript2 Week 3
22

33
## Agenda
44

5-
These are the topics for week 2:
5+
These are the topics for week 3:
66

7-
1. SPA vs. MPA
8-
- sfsdf
9-
- sdf
10-
2. Scope
11-
- sdfsd
12-
- asdas
7+
1. Scope
8+
9+
- Global vs. local (function and block)
10+
- Const and let
11+
12+
2. Hoisting
1313
3. Closures
1414

15-
## 1. What is a library?
15+
## 2. Scope
16+
17+
## 3. Closures
18+
19+
- [Understanding Closures](https://www.youtube.com/watch?v=rBBwrBRoOOY)
20+
21+
## 4. Developer Tools
1622

17-
## 2. What is jQuery?
23+
- [Google Chrome Developer Tools Crash Course](https://www.youtube.com/watch?v=8aGhZQkoFbQ)
1824

1925
## Finished?
2026

assets/javascript-sync-vs-async.png

17.2 KB
Loading

0 commit comments

Comments
 (0)