Why is the first if statement?


#1

if(i % 3===0 && i % 5===0){
console.log("FizzBuzz");
}


#2

This conditional needs to be the first comparison else 'FizzBuzz' will never print. Even though this is a 4-way conditional branch, flow can only ever take one branch which leads out of the statement.

3 && 5 ?  ->  no  ->  3 ?  ->  no  ->  5 ?  ->  no   -> i
       |                |                |              |
      yes              yes              yes             |
       |                |                |              |
       v                v                v              |
    FizzBuzz           Fizz             Buzz            |
       |                |                |              v
        ->               ->               ->           i++  -> for()