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
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,8 +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
141
-
> always do what you expect.
140
+
> It is safer to use `===` and `!==` as they will always do what you expect.
142
141
143
142
The `>` and `<` operators are "greater than" and "less than". You can
144
143
use them to tell which of two numbers is bigger.
@@ -155,7 +154,7 @@ var lessStudents = students < pizzas;
155
154
console.log('Are there fewer students than pizzas?'+ lessStudents);
156
155
157
156
```
158
-
> Play around with changing the `coaches`, `students` and `pizzas`variable numbers to familiarise yourself with it more.
157
+
> Play around with changing the `coaches`, `students` and `pizzas` variable numbers to familiarise yourself with operators.
159
158
160
159
You can also combine operators.
161
160
@@ -210,9 +209,15 @@ if (totalPeople > pizzas) {
210
209
211
210
#### Ternaries - Additional learning
212
211
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.
212
+
You may also see if/else statements written slightly differently.
214
213
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:
214
+
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.
215
+
216
+
```js
217
+
condition ? expression1 : expression2
218
+
```
219
+
220
+
Using the people and pizza example we wrote above and using the Ternary Operator instead of if/else it would look like this:
216
221
217
222
```js
218
223
totalPeople > pizzas
@@ -304,7 +309,7 @@ Even though `while` loops are simpler than `for` loops, it is more common to see
304
309
305
310
An array is a simple *data structure*. It can hold a list of elements of the same or different types (e.g. strings, numbers, booleans). In an array each element can be accessed using the **index**.
306
311
307
-
Confusingly, the first index of an array is 0, not 1.
312
+
Confusingly, the first index of an array in JavaScript is 0, not 1.
308
313
309
314
To understand this better, let's create an array of strings.
310
315
@@ -319,7 +324,7 @@ To retrieve an item from the array, we use **square bracket notation**
319
324
320
325
To get the first item `animals[0]`, the second `animals[1]` etc.
321
326
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])
327
+
> 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