8000 Improve section about operators. (#28) · muses-code-js/js-intro-workshop@badce62 · GitHub
[go: up one dir, main page]

Skip to content

Commit badce62

Browse files
leftclickbenButenkoT
authored andcommitted
Improve section about operators. (#28)
+ Change `==` to `===` and `!=` to `!==`. + Add note about not using `==` and `!=`. + Add point about the result of a comparison operator being a boolean. + Some whitespace cleanup.
1 parent 60176d5 commit badce62

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

js/level1.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@
211211
} else {
212212
do something else
213213
}
214+
214215
Example:
216+
215217
var number = 7;
216218
if (number > 7) {
217219
console.log('Our number is bigger than 7');
@@ -226,19 +228,29 @@
226228
227229
Earlier we introduced JavaScript's arithmetic operators. Now comes time to
228230
introduce you to the next set. JavaScript's Comparison operators' are used
229-
to compare values(>, <, <=, =>, ==, !=). Most of them you know from math
230-
classes in school, some of them can be new for you, so '==' is checking
231-
equality, if two values are equal.
231+
to compare values(>, <, <=, =>, ===, !==). Most of them you know from math
232+
classes in school, some of them can be new for you:
233+
234+
* === checks equality, results in true if two values are equal.
235+
* !== checks inequality, results in true if two values are not equal.
236+
237+
PS: Don't mix up '=' and '===' as they have different meanings.
238+
239+
Note: There are also '==' and '!=' operators, which are very similar to '==='
240+
and '!==', but with a slightly different meaning that is more prone to
241+
programming errors, so you should always use '===' and '!=='.
232242
233-
'!=' - Checks if they are not equal.
243+
The result of a comparison operator is a boolean value (true or false).
244+
For example:
234245
235-
PS: Don't mix up '=' and '==' as they have different meanings.
246+
* 3 < 4 is true.
247+
* 1 + 1 === 3 is false.
236248
*/
237249

238250
// TODO: So now we have 2 functions from the previous task - add and subtract.
239251
// Let's tell the machine to decide what action to run depending on the arithmetical
240-
// operator(+,-,/, * etc). If the operator is '+', we should use the add function, else we should use the
241-
// - subtract function.
252+
// operator (+,-,/, * etc). If the operator is '+', we should use the add function,
253+
// else we should use the subtract (-) operator.
242254
//
243255
// Step 1 - Create a variable called operator and let it be equal to '-'.
244256
// Step 2 - Create an if/else statement based on what operator we have.

0 commit comments

Comments
 (0)
0