Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Number isFinite() Method

JavaScript Number.isFinite() Method

Number Object Reference JavaScript Number object

Example

Check whether the parameter is infinite:

Number

.

isFinite

(

123

)

//

true

Number

.

isFinite

(

1.23

)

//

true

Number

.

isFinite

(

5

2

)

//

true

Number

.

isFinite

(

0

)

//

true

Number

.

isFinite

(

'

123

'

)

//

false

Number

.

isFinite

(

'

Hello

'

)

//

false

Number

.

isFinite

(

'

2005/12/12

'

)

//

false

Number

.

isFinite

(

Infinity

)

//

false

Number

.

isFinite

(

Infinity

)

//

false

Number

.

isFinite

(

0

/

0

)

//

false

Try it »


Definition and Usage

Number.isFinite() is a built-in method in JavaScript used to determine whether a value is a finite number (that is, a normal number rather than Infinity, -Infinity, or NaN).

isFinite() is part of the Number object and is used to ensure that a value is a valid, finite numeric type.

Tip: If number is NaN (not a number), or a positive/negative infinity, it returns false.

Number.isFinite() differs from the global isFinite() isFinite() function, as itNumber.isFinite() does not perform type conversion, but strictly determines value whether the value is a finite number. In comparison, theisFinite() global isFinite() method first converts its argument to a number before making the judgment.

1. Basic Usage

Example

console.

log

(

Number

.

isFinite

(

2

)

)

;

       

// true: 2 is a finite number

console.

log

(

Number

.

isFinite

(

3.14

)

)

;

   

// true: 3.14 is a finite number

console.

log

(

Number

.

isFinite

(

100

)

)

;

   

// true: -100 is a finite number

console.

log

(

Number

.

isFinite

(

1

/

0

)

)

;

   

// false: Infinity is not a finite number

console.

log

(

Number

.

isFinite

(

1

/

0

)

)

;

 

// false: -Infinity is not a finite number

console.

log

(

Number

.

isFinite

(

NaN

)

)

;

     

// false: NaN is not a finite number

console.

log

(

Number

.

isFinite

(

'2'

)

)

;

     

// false: '2' is a string, not a number

2. Number.isFinite() vs isFinite()

Example

console.

log

(

isFinite

(

2

)

)

;

       

// true: the global isFinite converts the type

console.

log

(

isFinite

(

'2'

)

)

;

     

// true: the string '2' is converted to the number 2

console.

log

(

Number

.

isFinite

(

2

)

)

;

 

// true: 2 is a finite number

console.

log

(

Number

.

isFinite

(

'2'

)

)

;

// false: the string '2' is not of number type

3. NaN and Infinity

Example

console.

log

(

Number

.

isFinite

(

NaN

)

)

;

     

// false: NaN is not a finite number

console.

log

(

Number

.

isFinite

(

Infinity

)

)

;

 

// false: Infinity is not a finite number

console.

log

(

Number

.

isFinite

(

Infinity

)

)

;

// false: -Infinity is not a finite number

4. Type Conversion

The Number.isFinite() method does not automatically convert the passed value to a number, so it is strict when judging. For values of other types, it directly returns false.

Example

console.

log

(

Number

.

isFinite

(

true

)

)

;

   

// false: the boolean value true is not a number

console.

log

(

Number

.

isFinite

(

undefined

)

)

;

// false: undefined is not a number

console.

log

(

Number

.

isFinite

(

null

)

)

;

   

// false: null is not a number


Browser support

Method
Number.isFinite() 19 12.0 16 9 22

Syntax



Number.isFinite(value)

Parameter value

Parameters Description
value The value to be tested, which can be data of any type (for example: numbers, strings, objects, booleans, etc.).

Return Value

Type Description
Boolean If value is a finite number, return true.
If value is not a finite number (for example: NaN, Infinity, -Infinity, or a non-numeric type), return false.

Technical Details

JavaScript version: ECMAScript 6

Number Object Reference JavaScript Number object