typeof(Infinity)
Number
以JavaScript返回。
但是为什么不x.isNaN, where x = 1/0
回来Number
呢?
样例代码:
var x = 1/0;
document.write(typeof(x)); //returns Number
document.write(x.isNaN); //return undefined
PS:我是Java语言的新手,可以从W3Schools学习它。如果您能指导我使用其他可靠的资源,我将非常高兴。
isNan
不是任何数量的属性。isNaN
但是,它既是全局范围内的函数,也是Number
对象上的函数。(随着后者的更新/更强大的版本)
由于isNaN
是一个函数,因此您必须将要检查的变量作为参数传递:
isNaN(x)
或Number.isNaN(x)
将按true
预期返回。
之所以document.write(x.isNaN);
返回undefined
,是因为x
(a Number
)没有属性isNan
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句