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
Note: You can ask students to explain a concept or summerise the last lecture themselves
29
+
Note: You can ask students to explain a concept or summarize the last lecture themselves
30
30
31
31
## 2. Function (ES5 only)
32
32
33
33
### Explanation
34
+
34
35
Functions are a way to organize your code in to re-usable chunks.
35
36
36
37
> People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones.
Create a function that takes a string and returns the first letter of each word in the string.
50
+
51
+
```javascript
52
+
firstLetter(`Hack Your Future`);
53
+
// will return: 'HYF'
54
+
```
55
+
45
56
### Essence
46
-
-__Reusability__: Functions can be grouped together to make a module (or library), and then modules can be imported into your application so you can build awesome apps!
47
-
-__Abstraction__: Hide underlying details about how a piece of functionality works under the hood. You can change how things are implemented within the function without other programmers who use your function worrying aobut the exact details of how it was implemented.
57
+
58
+
-**Reusability**: Functions can be grouped together to make a module (or library), and then modules can be imported into your application so you can build awesome apps!
59
+
-**Abstraction**: Hide underlying details about how a piece of functionality works under the hood. You can change how things are implemented within the function without other programmers who use your function worrying about the exact details of how it was implemented.
48
60
49
61
And the same link as Explanation
50
62
@@ -53,18 +65,19 @@ SECOND HALF (14.00 - 16.00)
53
65
## 3. Scope (global, functional, block)
54
66
55
67
### Explanation
56
-
Scopes define the visiblity of declarations of variables and functions.
57
68
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.
69
+
Scopes define the visibility of declarations of variables and functions.
70
+
71
+
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.
59
72
60
73
-`var` and `function` declarations are visible with function 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({}).
74
+
-`let` and `const` declarations are visible with block scope. A block can be seen as a set of statements enclosed in curly brackets(`{}`).
62
75
63
76
Global scope:
64
77
65
78
- Can be a real useful tool or a nightmare.
66
79
- 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.
80
+
- Big risk of causing problems called namespace clashes with multiple variables with same name being created in different places.
68
81
69
82
Local Scope:
70
83
@@ -73,31 +86,35 @@ Local Scope:
73
86
- 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