1 + undefined = ?
what
1 + undefined = NaN
When you do 1 + "undefined"
you concatinate the 1 to the String "undefined"
resulting in the string "1undefined"
undefined is nothing or like Null in other languages (variable is not set)
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)
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.
NaN
is the result of a failed Number
operation.
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. Any Number operation with NaN
will result in NaN
as well.