|
211 | 211 | } else {
|
212 | 212 | do something else
|
213 | 213 | }
|
| 214 | +
|
214 | 215 | Example:
|
| 216 | +
|
215 | 217 | var number = 7;
|
216 | 218 | if (number > 7) {
|
217 | 219 | console.log('Our number is bigger than 7');
|
|
226 | 228 |
|
227 | 229 | Earlier we introduced JavaScript's arithmetic operators. Now comes time to
|
228 | 230 | 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 '!=='. |
232 | 242 |
|
233 |
| - '!=' - Checks if they are not equal. |
| 243 | + The result of a comparison operator is a boolean value (true or false). |
| 244 | + For example: |
234 | 245 |
|
235 |
| - PS: Don't mix up '=' and '==' as they have different meanings. |
| 246 | + * 3 < 4 is true. |
| 247 | + * 1 + 1 === 3 is false. |
236 | 248 | */
|
237 | 249 |
|
238 | 250 | // TODO: So now we have 2 functions from the previous task - add and subtract.
|
239 | 251 | // 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. |
242 | 254 | //
|
243 | 255 | // Step 1 - Create a variable called operator and let it be equal to '-'.
|
244 | 256 | // Step 2 - Create an if/else statement based on what operator we have.
|
|
0 commit comments