Probably a very basic question from a confused javascript noob…
Why do
var hasthisvalue = null;
if (hasthisvalue)
print("hasthisvalue hs value");
and
var hasthatvalue = "";
if (hasthatvalue)
print("hasthatvalue has value");
don’t print anything, but if I combine these two
var combined = "hasthisvalue" + "hasthatvalue";
if (combined)
print ("combined has value");
it does?
Or more directly:
var combined = null + "";
if (combined)
print ("combined has value");
Why does “combined” has a value if I only add two variables that don’t have values? What am I missing?
When you compare them separately, each converts to
falsein theifcheck. When you combine them, thenullbecomes the string"null", so their concatenation is the string"null", which does not convert tofalse