内容目录
isFinite()函数用于判断指定数字是否是有限值。如果指定的数字为NaN、正无穷、负无穷,则返回false,其他数字均返回true。
该函数属于Global对象,所有主流浏览器均支持该函数。
语法
isFinite( number )
参数
| 参数 | 描述 |
|---|---|
| number | Number类型指定的数值。 |
如果参数number不是Number类型(如字符串、函数等),也返回false。
返回值
isFinite()函数的返回值是Boolean类型。如果指定的数字为NaN、正无穷、负无穷,则返回false,其他数字均返回true。
示例&说明
document.writeln( isFinite( 18 ) ); // true
document.writeln( isFinite( 12.5 ) ); // true
// 非数字值
document.writeln( isFinite( NaN ) ); // false
// 负无穷
document.writeln( isFinite( Number.NEGATIVE_INFINITY ) ); // false
// 正无穷
document.writeln( isFinite( Number.POSITIVE_INFINITY ) ); // false
// 正无穷
document.writeln( isFinite( Infinity ) ); // false
// 字符串
document.writeln( isFinite( "CodePlayer" ) ); // false
// undefined
document.writeln( isFinite( undefined ) ); // false

0 条评论
撰写评论