可能从一个困惑的javascript小白一个非常基本的问题...为什么var combined = null +“”有一个值?
为什么
var hasthisvalue = null;
if (hasthisvalue)
print("hasthisvalue hs value");
和
var hasthatvalue = "";
if (hasthatvalue)
print("hasthatvalue has value");
不显示任何信息,但如果我结合这两种
var combined = "hasthisvalue" + "hasthatvalue";
if (combined)
print ("combined has value");
它呢?
或者更直接:
var combined = null + "";
if (combined)
print ("combined has value");
为什么“组合拳”有一个值,如果我只补充一点,没有价值的两个变量?我错过了什么?
因为非空字符串是真正的值。 'null +“”'是字符串'“null”'。 – MaxArt
第二个,你的转换。首先,我认为你的意思与众不同。 –
在第一种情况下,您串联2个字符串,而不是变量。 – Ixx