Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

JavaScript 特殊数字值 NaN



Recommended Posts

  • NaN是唯一一个不和自身不相等的值,Array》prototype.indexOf 使用了严格相等,因此不能通过该方法在数组中查找 NaN:

    NaN === NaN // false
    [NaN].indexof(NaN); // false

    如果想要检查一个值是否为 NaN,必须使用全局函数 isNaN():

    isNaN(NaN); // true
    isNaN(33); // false

    但是,isNaN 对非数字不起作用,最好是把 isNaN 和类型检查组合起来:

    function checkNaN(value) {
      return typeof value === 'number' && isNaN(value);

    或者,可以检查这个值是否和它本身不相等,因为 NaN 是唯一有这样特征的值:

    function checkNaN(value) {
      return vlaue !== value;
Link to post
Link to comment
Share on other sites


discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    • Create New...