Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Safe Integer Check

Fundamentals: Part 1medium

Course · Section 2: JavaScript Fundamentals – Part 1 · Lecture 11: Data Types

Implement `isSafeInt(n)` returning whether `n` is a safe integer.

Sample tests

Input: isSafeInt(10)
Output: true
Input: isSafeInt(10.1)
Output: false

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • isSafeInteger is stricter than isInteger; values beyond 2^53-1 are unsafe.

Learning resources

  • MDN: typeof
Approach & explanation (try first)

Safe integers are whole numbers representable exactly in a double, which Number.isSafeInteger checks directly.

Loading...
⌘/Ctrl + Enter

Run your code to see results.