您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月11日 06:38

原创 JavaScript isFinite() 函数详解

2324 次浏览 读完需要≈ 4 分钟

内容目录

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

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单