$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #245

Which fix removes the bug?

const n = Number(input);
if (n === NaN) {
  showError(); // never runs
}
  1. Test with Number.isNaN(n)
  2. Use n == NaN instead
  3. Use typeof n === 'NaN'
  4. Compare n === undefined
NaN is not equal to anything, including itself, so both == and === comparisons are always false. Number.isNaN checks for it directly.
Play Problem Solving ▸