Skip to content

Files

Latest commit

 

History

History
23 lines (17 loc) · 659 Bytes

number-arg-out-of-range.md

File metadata and controls

23 lines (17 loc) · 659 Bytes

Pattern: Invalid number method argument

Issue: -

Description

Number methods like toString, toFixed, toExponential, and toPrecision have specific valid ranges for their arguments. Using values outside these ranges will cause errors or unexpected results.

Examples

Example of incorrect code:

number.toString(37);  // radix must be 2-36
number.toFixed(21);   // precision must be 0-20
number.toPrecision(0);  // precision must be 1-21

Example of correct code:

number.toString(16);  // valid hexadecimal
number.toFixed(2);    // two decimal places
number.toPrecision(5);  // five significant digits