From 06fb850a159e89922670842356e005feef32470d Mon Sep 17 00:00:00 2001 From: Ben New Date: Sat, 30 Jun 2018 17:41:29 +0800 Subject: [PATCH] Improve section about operators. + 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. --- js/level1.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/js/level1.js b/js/level1.js index ff87e17..927c0b8 100644 --- a/js/level1.js +++ b/js/level1.js @@ -211,7 +211,9 @@ } else { do something else } + Example: + var number = 7; if (number > 7) { console.log('Our number is bigger than 7'); @@ -226,19 +228,29 @@ Earlier we introduced JavaScript's arithmetic operators. Now comes time to introduce you to the next set. JavaScript's Comparison operators' are used - to compare values(>, <, <=, =>, ==, !=). Most of them you know from math - classes in school, some of them can be new for you, so '==' is checking - equality, if two values are equal. + to compare values(>, <, <=, =>, ===, !==). Most of them you know from math + classes in school, some of them can be new for you: + + * === checks equality, results in true if two values are equal. + * !== checks inequality, results in true if two values are not equal. + + PS: Don't mix up '=' and '===' as they have different meanings. + + Note: There are also '==' and '!=' operators, which are very similar to '===' + and '!==', but with a slightly different meaning that is more prone to + programming errors, so you should always use '===' and '!=='. - '!=' - Checks if they are not equal. + The result of a comparison operator is a boolean value (true or false). + For example: - PS: Don't mix up '=' and '==' as they have different meanings. + * 3 < 4 is true. + * 1 + 1 === 3 is false. */ // TODO: So now we have 2 functions from the previous task - add and subtract. // Let's tell the machine to decide what action to run depending on the arithmetical -// operator(+,-,/, * etc). If the operator is '+', we should use the add function, else we should use the -// - subtract function. +// operator (+,-,/, * etc). If the operator is '+', we should use the add function, +// else we should use the subtract (-) operator. // // Step 1 - Create a variable called operator and let it be equal to '-'. // Step 2 - Create an if/else statement based on what operator we have.