JavaScript Integer Safety — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Integer Safety lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Check for a whole number
easy10 minReport whether 42.5 is an integer.
- 2
Read the safe limit
easy10 minReport the largest safe integer.
- 3
Spot an unsafe value
easy10 minReport whether a value beyond the limit is safe.
- 4
Use a BigInt
easy10 minReport the type of a BigInt literal.
- 5
Stay exact with BigInt
medium10 minShow that BigInt keeps two large values distinct.
Find the bug(5)
- 1
Fix typeof used to check an integer
easy8 mintypeof says number for any number, whole or not.
- 2
Fix the unsafe comparison
easy8 minBeyond the safe limit two different values compare as equal.
- 3
Fix BigInt mixed with a number
easy8 minA BigInt cannot be added to an ordinary number.
- 4
Fix isInteger used for safety
easy8 minA value can be a whole number and still be beyond the safe limit.
- 5
Fix the missing n suffix
easy8 minWithout the n it is an ordinary number, not a BigInt.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace