Skip to main content

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. 1

    Check for a whole number

    easy10 min

    Report whether 42.5 is an integer.

  2. 2

    Read the safe limit

    easy10 min

    Report the largest safe integer.

  3. 3

    Spot an unsafe value

    easy10 min

    Report whether a value beyond the limit is safe.

  4. 4

    Use a BigInt

    easy10 min

    Report the type of a BigInt literal.

  5. 5

    Stay exact with BigInt

    medium10 min

    Show that BigInt keeps two large values distinct.

Find the bug(5)

  1. 1

    Fix typeof used to check an integer

    easy8 min

    typeof says number for any number, whole or not.

  2. 2

    Fix the unsafe comparison

    easy8 min

    Beyond the safe limit two different values compare as equal.

  3. 3

    Fix BigInt mixed with a number

    easy8 min

    A BigInt cannot be added to an ordinary number.

  4. 4

    Fix isInteger used for safety

    easy8 min

    A value can be a whole number and still be beyond the safe limit.

  5. 5

    Fix the missing n suffix

    easy8 min

    Without 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