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
Ask students to explain a concept or summerise the last lecture themselves
45
-
### Essence
29
+
Note: You can ask students to explain a concept or summerise the last lecture themselves
46
30
47
-
## 2. What is a function (ES5 only)
31
+
## 2. Function (ES5 only)
48
32
49
33
### Explanation
50
34
Functions are a way to organize your code in to re-usable chunks.
@@ -66,15 +50,27 @@ And the same link as Explanation
66
50
67
51
SECOND HALF (14.00 - 16.00)
68
52
69
-
## 3. Wat is scope (global, functional, block)
53
+
## 3. Scope (global, functional, block)
70
54
71
55
### Explanation
72
56
Scopes define the visiblity of declarations of variables and functions.
73
57
74
-
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.
58
+
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.
75
59
76
60
-`var` and `function` declarations are visible with function scope.
77
-
-`let` and `const` declarations are visible with block scope.
61
+
-`let` and `const` declarations are visible with block scope. A block can be seen as a set of statements enclosed in curly brackets({}).
62
+
63
+
Global scope:
64
+
65
+
- Can be a real useful tool or a nightmare.
66
+
- Useful in scenarios where we want to export JS modules, use third party libraries like jQuery etc.
67
+
- Big risk of causing namespace clashes with multiple variables with same name being created in different places.
68
+
69
+
Local Scope:
70
+
71
+
- Think of local scope as any new scope that is created within the global scope.
72
+
- Each function written in JavaScript creates a new local scope.
73
+
- 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