Simplify nested if/else with repeated results?

You could check with the result of the first check. This is an exclusive OR check. // typeof inverse === ‘boolean’ function handleDirection(src) { if (src === ‘left’ === inverse) { tracker–; } else { tracker++; } } The check evaluates the expression in this order (src === ‘left’) === inverse: src === ‘left’ === … Read more

Why does non-equality check of one variable against many values always return true?

Use &&/AND/and, not ||/OR/or: v != “x” && v != “y” && v != “z” Problem If an if block is always executed, the condition for the if block always evaluates to true. The logical expression must be wrong. Let us consider v != “x” || v != “y” || v != “z” for each … Read more