You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Week3/LESSONPLAN.md
+65-9Lines changed: 65 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -12,20 +12,76 @@ The purpose of this class is to introduce to the student:
12
12
13
13
FIRST HALF (12.00 - 13.30)
14
14
## 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
19
19
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)
21
23
### 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.
0 commit comments