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

Skip to content

Commit 04e4840

Browse files
authored
Update LESSONPLAN.md
1 parent 219e8bf commit 04e4840

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

Week3/LESSONPLAN.md

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,76 @@ The purpose of this class is to introduce to the student:
1212

1313
FIRST HALF (12.00 - 13.30)
1414
## 1. Q&A about last week's concepts & homework
15-
### Explanation
16-
### Example
17-
### Exercise
18-
### Essence
15+
- synchronous vs. asynchronous
16+
- callbacks
17+
- eventloops
18+
- map, filter, reduce
1919

20-
## 2.The importance of scope (global, functional and block)
20+
Note: You can ask students to explain a concept or summerise the last lecture themselves
21+
22+
## 2. Scope (global, functional and block)
2123
### Explanation
24+
Scopes define the visiblity of declarations of variables and functions.
25+
26+
The top level outside all your functions is called the _global scope_. Values defined in the global scope are accessible from everywhere in the code. Whereas, variables defined in local scope can only be accessed and altered inside the scope they were created.
27+
28+
- `var` and `function` declarations are visible with function scope.
29+
- `let` and `const` declarations are visible with block scope. A block can be seen as a set of statements enclosed in curly brackets({}).
30+
31+
Global scope:
32+
33+
- Can be a real useful tool or a nightmare.
34+
- Useful in scenarios where we want to export JS modules, use third party libraries like jQuery etc.
35+
- Big risk of causing namespace clashes with multiple variables with same name being created in different places.
36+
37+
Local Scope:
38+
39+
- Think of local scope as any new scope that is created within the global scope.
40+
- Each function written in JavaScript creates a new local scope.
41+
- Variables defined within a function aren't available outside it. They are created when a function starts and are _in a way_ destroyed/hidden when a function ends.
42+
43+
https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/scope.md
2244
### Example
45+
![Scopes](../assets/scopes.png)
46+
47+
```Javascript
48+
let villan = "Joker"; // | global scope
49+
// |
50+
function myFunction() { // | | function scope
51+
let hero = "Batman"; // | |
52+
if (hero === "Batman") { // | | | block scope
53+
let coHero = "Robin"; // | | |
54+
console.log(hero); // | | |
55+
console.log(coHero); // | | |
56+
console.log(villan); // | | |
57+
} // | | |
58+
console.log("------") // | |
59+
console.log(hero); // | |
60+
console.log(coHero); // | |
61+
console.log(villan); // | |
62+
} // | |
63+
// |
64+
myFunction(); // |
65+
```
66+
67+
And the same link as Explanation
2368
### Exercise
69+
What happens if we use the same variable name in different scopes?
70+
71+
```Javascript
72+
function myFunction() {
73+
let hero = "Batman";
74+
if (true) {
75+
let hero = "The Flash";
76+
console.log(hero);
77+
}
78+
console.log(hero);
79+
}
80+
81+
myFunction();
82+
```
2483
### Essence
25-
Notes:
26-
27-
- It determines the accessibility of variables
28-
- Variables defined inside a function are not accessible (visible) from outside the function.
84+
Same link as Explanation
2985

3086
## 3. What hoisting is and the difference between compile time and run time
3187
### Explanation

0 commit comments

Comments
 (0)