Which fix removes the bug?
const age: number = parseInt(input); if (age > 18) grant();
- Check the result for
NaN - Pass a radix to
parseInt - Type
ageasstringtoo - Use
>=instead of>
parseInt returns NaN on bad input, and every comparison with NaN is false.
Play Problem Solving ▸