Why this matters
Validating numbers without isFinite can lead to unexpected behavior with NaN or Infinity, which can cause runtime errors.
Ensure that isFinite is used to validate numbers. Without this, NaN or Infinity can cause unexpected behavior and runtime errors.
Validating numbers without isFinite can lead to unexpected behavior with NaN or Infinity, which can cause runtime errors.
Side-by-side examples engineers can pattern-match during review.
const value = Number("Not a Number");
if (value) {
console.log("Valid number"); // Will not catch NaN or Infinity
}const value = Number("Not a Number");
if (isFinite(value)) {
console.log("Valid number");
}
const value = Number("Not a Number");
if (value) {
console.log("Valid number"); // Will not catch NaN or Infinity
}const value = Number("Not a Number");
if (isFinite(value)) {
console.log("Valid number");
}
From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.