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: js/lesson2/tutorial.md
+11-5Lines changed: 11 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,7 +137,7 @@ console.log('Apples and oranges are different: ' + notEqual);
137
137
```
138
138
139
139
> You may also see `==` and `!=`, these are similar but have some quirks so it's generally recommended to avoid them.
140
-
> You can simply use `===` and `!==`and they will
140
+
> It is safer to use `===` and `!==`as they will always do what you expect
141
141
> always do what you expect.
142
142
143
143
The `>` and `<` operators are "greater than" and "less than". You can
@@ -155,7 +155,7 @@ var lessStudents = students < pizzas;
155
155
console.log('Are there fewer students than pizzas?'+ lessStudents);
156
156
157
157
```
158
-
> Play around with changing the `coaches`, `students` and `pizzas`variable numbers to familiarise yourself with it more.
158
+
> Play around with changing the `coaches`, `students` and `pizzas` variable numbers to familiarise yourself with more with the operators.
159
159
160
160
You can also combine operators.
161
161
@@ -210,9 +210,15 @@ if (totalPeople > pizzas) {
210
210
211
211
#### Ternaries - Additional learning
212
212
213
-
In the latest versions of JavaScript you may see if/else statements written slighlty differently. We believe teaching the above way first helps cement how they work, however if you're working with a code base that uses the latest JavaScript you will see it written this way.
213
+
You may also see if/else statements written slighlty differently.
214
214
215
-
The condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:) and finally the expression to execute if the condition is falsy. For example:
215
+
The condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:) and finally the expression to execute if the condition is falsy.
216
+
217
+
```js
218
+
condition ? expression1 : expression2
219
+
```
220
+
221
+
Using the people and pizza example we wrote above and using the Ternary Operator instead of if/else it would look like this:
216
222
217
223
```js
218
224
totalPeople > pizzas
@@ -319,7 +325,7 @@ To retrieve an item from the array, we use **square bracket notation**
319
325
320
326
To get the first item `animals[0]`, the second `animals[1]` etc.
321
327
322
-
> Create an array that includes 5 names and then access the 3rd item in the array? (don't forget to access the third item in the array you won't be doing [3])
328
+
> Create an array that includes 5 names and then access the 3rd item in the array. (don't forget to access the third item in the array you won't be doing [3])
0 commit comments