[英]what's the result of 1 + undefined
1 + undefined = ?
what's wrong? 怎么了?
I run it in chrome console ,it return NaN
. 我在chrome控制台中运行它,返回
NaN
。
can you pls explain the result? 你能解释一下结果吗?
I think it should be "1undefined". 我认为应该是“ 1undefined”。 tks
ks
NaN
is the result of a failed Number
operation. NaN
是Number
操作失败的结果。
1 + undefined // NaN
"1" + undefined // "1undefined"
1 + "" + undefined // "1undefined"
1 + ("" + undefined) // "1undefined"
typeof NaN // "number"
typeof undefined // "undefined"
NaN === NaN // false (it's not reflexive!)
undefined === undefined // true (it's reflexive)
NaN.toString() // "NaN"
NaN
means Not a Number where a number was expected. NaN
表示不是预期的数字的数字。 Any Number operation with NaN
will result in NaN
as well. 使用
NaN
任何Number运算也将导致NaN
。
1 + undefined = NaN 1 +未定义= NaN
When you do 1 + "undefined"
you concatinate the 1 to the String "undefined"
resulting in the string "1undefined"
当您执行
1 + "undefined"
,会将1隐含在字符串"undefined"
得到字符串"1undefined"
undefined is nothing or like Null in other languages (variable is not set) undefined没什么,或者像其他语言中的Null一样(未设置变量)
In Javascript null is an expected absense (set to null somewhere) of a value and undefined is an unexpected absense of a value (never set) 在Javascript中,null是值的预期缺失(在某处设置为null),而undefined是值的意外缺失(从未设置)
What do you want to accomplish? 你想要完成什么?
You expect a string concatenation, but this will only happen if you have at least one string. 您期望使用字符串连接,但是只有在至少有一个字符串的情况下,才会发生这种情况。 And in your example nothing is a string.
在您的示例中,没有什么是字符串。
1
is not a string and undefined
is not a string. 1
不是字符串,并且undefined
不是字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.