NaN 等于 NaN 吗? [英] Is NaN equal to NaN?

查看:47
本文介绍了NaN 等于 NaN 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

parseFloat("NaN")

返回NaN",但是

parseFloat("NaN") == "NaN"

返回假.现在,它确实返回 false 可能是一件好事,但我不明白这是怎么回事.JavaScript 创建者是否只是将其作为特例?因为否则我无法理解这是如何返回 false 的.

returns false. Now, that's probably a good thing that it does return false, but I don't understand how this is so. Did the JavaScript creators just make this a special case? Because otherwise I can't understand how this returns false.

推荐答案

当 JavaScript 函数返回 NaN 时,这不是文字字符串,而是全局空间中的对象属性.您不能将其与字符串 "NaN" 进行比较.

When a JavaScript function returns NaN, this is not a literal string but an object property in the global space. You cannot compare it to the string "NaN".

参见 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/NaN

这篇关于NaN 等于 NaN 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆