Pattern: Chained comparison operators
Issue: -
Comparison operators cannot be chained to compare multiple values at once. Each comparison returns a boolean, so subsequent comparisons are comparing against true/false rather than the actual values.
Example of incorrect code:
if (x === y === z) {
// Actually checks if (x === y) === z
}
if (a < b < c) {
// Actually checks if (a < b) < c
}
Example of correct code:
if (x === y && y === z) {
// Properly compares all values
}
if (a < b && b < c) {
// Properly checks range
}