1. If/else


"if (number % 2 === 0)"

why we use "=== 0" in this?


when you put an integer in place of the word number, then the expression becomes a basic math problem. Once it becomes a math problem, it then simply evaluates to either a true or false. (Either it's true that it equals === 0, or it's false and it does not).

Since modulo is basically a remainder math problem, the number would need to be divisible by 2 in order to evaluate as true.

Hope that helps?

  • % is a arithmetical operator called modulus. It returns what's extra in a division. For example, 5 % 2 returns 1, as 5 / 2 equals 2 and 1 is extra. If I am not wrong, all the arithmetical operators except for + wil convert a string with a number value into a number for doing the operation. + doesn't, because it will concatenate the string with whatever the other value is. Therefore, "10" % 5 will return 0.
  • '===' is a comparison operator called equal type and equal value. It compares, then, both type and value. The type would be boolean, string, number, etc. The value is the 'content' to say it in a way... The value of "6" is 6, the value of 6 is also 6, but it is a different type. Therefore, we can confirm the following lines are correct.

    "7" === 7 //False
    7 === 7 //True
    7 == "7" //True
    7 == 7 //True
    • '==' is a comparison operater called equal value. It only compares the value, not the type. You can see how it works in the example above.

Hope it helps :smile: