In this article, you’ll learn 12 JavaScript Number methods that you should know.

1. parseInt() Method

The parseInt() method parses the given string argument and returns an integer number parsed from the string.

Output:

If an integer can’t be parsed from the given string, the method returns NaN.

Output:

2. toString() Method

The toString() method returns the given number in the form of a string. This method accepts radix (the base in mathematical numeral systems) as an optional parameter and returns a string representing the specified Number object.

Output:

3. toExponential() Method

The toExponential() method returns a string that represents the exponential notation of the given number. This method accepts fractionDigits as an optional parameter that specifies the number of digits after the decimal point.

Output:

4. toFixed() Method

The toFixed() method returns a string that represents a number formatted using fixed-point notation. This method accepts an optional parameter that specifies the number of digits to appear after the decimal point. If no parameter is provided, the value of this parameter is treated as 0.

Output:

5. toPrecision() Method

The toPrecision() method returns a string representing the number to the specified precision. This method accepts an optional parameter that specifies the number of significant digits.

Output:

6. valueOf() Method

The valueOf() method returns the primitive value of a Number object.

Output:

7. toLocaleString() Method

The JavaScript toLocaleString() method returns a string with a language-sensitive representation of a number.

Output:

8. parseFloat() Method

The parseInt() method parses the given string argument and returns a floating-point number parsed from the string.

Output:

If a number can’t be parsed from the given string, the method returns NaN.

Output:

9. isInteger() Method

The isInteger() method checks whether the passed value is an integer. This method returns a Boolean value (true or false) that indicates whether the given value is an integer or not.

Output:

10. isFinite() Method

The isFinite() method checks whether the passed value is a finite number. This method returns a Boolean value (true or false) that indicates whether the given value is finite or not.

Output:

11. isSafeInteger() Method

The isSafeInteger() method checks whether a value is a safe integer. This method returns a Boolean value (true or false) that indicates whether the given value is a safe integer or not.

According to the official MDN Docs, a safe integer is an integer that:

can be exactly represented as an IEEE-754 double-precision number, and whose IEEE-754 representation cannot be the result of rounding any other integer to fit the IEEE-754 representation.

Output:

12. isNaN() Method

The isNaN() method checks whether a value is a NaN and its type is Number. This method returns true if the given value is NaN and its type is Number, otherwise, it returns false.

Output:

If you want to have a look at the complete source code used in this article, check out the GitHub repository.

Get Your JavaScript Basics Strong

JavaScript is one of the most popular programming languages used by web devs today. To develop amazing JavaScript-based projects, you first need to understand the fundamentals of the language. Get your hands dirty and solidify your JavaScript fundamentals.