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
###### 15. Indicate for each of these whether it is an expression or a statement:
38
+
39
+
1.`l`
40
+
2.`l = 4;`
41
+
3.`l == 4`
42
+
4.`if (l == 4) { console.log("yes"); }`
43
+
5.`console.log("yes");`
44
+
6.`"yes"`
45
+
7.`console.log(l == 4 ? "yes" : "no")`
46
+
8.`function a() { return 4; }`
47
+
9.`let a = function () { return 4; }`
48
+
49
+
###### Given the following code:
50
+
51
+
```js
52
+
let s ="Hello".toLowerCase();
53
+
let l =s.length;
54
+
55
+
functionsum(a, b) {
56
+
return a + b;
57
+
}
58
+
letmax=function (a, b) {
59
+
return a > b ? a : b;
60
+
}
61
+
62
+
let s1 =sum(4, 5);
63
+
let s2 =4+5;
64
+
65
+
if (s2 == s1) {
66
+
console.log("same");
67
+
} else {
68
+
console.log("not same");
69
+
}
70
+
```
71
+
72
+
**18. List all 11 *statements* in the code above**
73
+
74
+
**19. List all 28 *expressions* in the code above (BONUS!)**
75
+
76
+
##### Essence
77
+
It's important to know the difference between expressions and statement because:
78
+
1. It will give you an overview on what the code is about (is it an instruction or is code that resolves in a value)
79
+
2. While writing code you'll not mix up the two and therefore make sure that you do not write wrong code.
19
80
20
-
**Do Exercise**
21
81
22
82
3. What are operators (comparison, arithmetic, logical, assignment)
83
+
##### Explanation
84
+
An operator is capable of manipulating a certain value or operand. Operators are used to perform specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands. In JavaScript operators are used for compare values, perform arithmetic operations etc. There are various operators supported by JavaScript:
85
+
86
+
* Arithmetic Operators
87
+
take numerical values (either literals or variables) as their operands and return a single numerical value.
88
+
* Comparison Operators
89
+
Two diferent types of comparison operators; They will always return a logical value,
90
+
- Equality Operators
91
+
checks if the operands are 'the same'
92
+
diffference in '=' '==' '==='
93
+
- Relational Operators
94
+
checks if the specific relation between two operands is true or false
95
+
96
+
* Logical Operators
97
+
Mostly 'comparing'boolean values, but it can be used with any type.
98
+
99
+
* Assignment Operators
100
+
assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal '='
Operators are very important in a programming language, because this is how we manipulate values.
109
+
In fact, operators are the buildingblocks of all possible actions.
110
+
23
111
24
-
**Do Exercise**
25
112
26
113
SECOND HALF (14.00 - 16.00)
27
114
28
115
4. What are loops (do/while & for loop)
116
+
##### Explanation
117
+
Programming loops are about doing the same thing over and over again. Another term for that is: iteration
118
+
119
+
Wikipedia: In most computer programming languages, a while loop is a (control flow) statement that allows (a block of) code to be executed repeatedly based on a given Boolean condition.
29
120
30
-
**Do Exercise**
121
+
##### Example
122
+
*images*
123
+
##### Exercise
124
+
Make a for loop with a do-while loop
125
+
##### Essence
126
+
In programming you have to do a lot of (alomst) similar calculations over and over again. Using loops makes it iesier (and less boring) to code. Next to that it makes sure the the code is much more compact.
127
+
128
+
You can check: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Looping_code as well. underneath the paragraph: 'Why bother'
31
129
32
130
5. What are conditional statements (if/else & switch)
131
+
##### Explanation
132
+
The normal order of execution of statements in a computer program is in straight-line order, from top to bottom. However, sometimes it is desirable to execute one or more statements conditionally, i.e. depending on whether some condition – determined by the state of your program – holds true.
133
+
134
+
In its simplest form the `if` statement looks like this:
135
+
136
+
137
+
```js
138
+
if () {
139
+
}
140
+
```
141
+
142
+
Then we have:
143
+
```js
144
+
if() {
145
+
146
+
} else {
147
+
148
+
}
149
+
150
+
151
+
```
152
+
```js
153
+
if() {
154
+
155
+
} elseif {
156
+
157
+
}
158
+
```
159
+
160
+
Here, `condition` is a boolean expression that resolves to either `true` or `false` (or, more precisely, any expression that is 'truthy' or 'falsy', as will be explained later).
161
+
162
+
The statements within the curly braces `{` and `}` will be executed if the condition holds true, otherwise these statements will be skipped (i.e. ignored).
163
+
164
+
165
+
166
+
The switch statement can sometimes be a useful alternative to a concatenation of if statements. This is the case when the condition is an expression that can be decomposed into a number of distinct values or cases, as shown in the example below.
0 commit comments