`
bcyy
  • 浏览: 1831141 次
文章分类
社区版块
存档分类
最新评论

奇怪的js NaN and Infinity

 
阅读更多

Parsing something that isn't a number results in NaN. isNaN helps to detect those cases:

  1. parseInt("hello",10)//NaN
  2. isNaN(parseInt("hello",10))//true

Division through zero results in Infinity:

  1. 1/0//Infinity

Both NaN and Infinity are of type "number":

  1. typeofNaN//"number"
  2. typeofInfinity//"number"

Note that NaN compares in a strange way:

  1. NaN==NaN//false(!)

But:

  1. Infinity==Infinity//true
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics