Explain JavaScript Numeric Edge Cases
Company: Riotgames
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: easy
Interview Round: Technical Screen
# Explain JavaScript Numeric Edge Cases
Explain how JavaScript distinguishes numeric values, integers, `NaN`, and infinities. Compare `typeof`, `Number.isInteger`, `Number.isNaN`, `Number.isFinite`, numeric conversion, and partial string parsing. Correct the assumption that a standard `Number.isNumber` method exists.
### Constraints & Assumptions
- Discuss primitive numbers; mention `BigInt` only where it changes the boundary.
- Include coercion and safe-integer precision pitfalls.
### Clarifying Questions to Ask
- Is the goal validation of already typed values or parsing user input?
- Should numeric strings be accepted, and must the entire string be valid?
```hint Separate type, finiteness, and integrality
No single check answers all three questions, and parsing adds a separate coercion policy.
```
### What a Strong Answer Covers
- Accurate behavior for `NaN`, positive and negative infinity, and `-0`.
- Non-coercing `Number` predicates versus coercing global functions.
- Whole-string conversion versus prefix parsing.
- `Number.isSafeInteger` and precision beyond the safe range.
### Follow-up Questions
- How would you validate a form field that must be a finite safe integer?
- Why can a mathematically non-integer decimal be represented as an integer after rounding?
Overview: Explain JavaScript numeric classification and parsing behavior, including integer checks, NaN, and Infinity edge cases.