[Javascript] Identify and Deal with NaN in JavaScript

Dealing with the special NaN value can be tricky in JavaScript. It behaves like a number and not a number at the same time. This lesson explains how to identify it using the isNaN function or the Number.isNaN method.

 

Number.isNaN = Number.isNaN  || function(x) {x !== x} 

 

Number.isNaN(NaN) // true
Number.isNaN("JS") // false
Number.isNaN("") // false

 

posted @ 2017-02-06 02:46  Zhentiw  阅读(175)  评论(0编辑  收藏  举报