Also, and just for clarity. Say you wanted to check if a variable was either 1 or 2. Do not be tricked by how it's said out loud, because computers don't speak english.
bad and wrong:
if( my_var == 1 || 2 ) {
log( "this is wrong!" );
}
That statement is wrong because it's making two checks:
- is (my_var == 1) true?
- is (2) true?
Since 2 is always true (in verge, like C, only the number 0 is false), that if-statement will alwys execute, regardless of whether my_var is 1 or 2.
The following is how to properly write that statement:
good and strong:
if( my_var == 1 || my_var == 2 ) {
log( "my_var is either equal to 1 or 2!!!" );
}
Now you know. And knowing is half the battle :)