Answer the question
In order to leave comments, you need to log in
js type conversion. Why undefined + 1 = NaN?
It would seem that "+" starts the conversion to a string and concatenation.
I would expect
undefined + 1 = String(undefined) + 1 = 'undefined' + 1 = 'undefined1'
In fact
undefined + 1 = NaN
Why is that? How is the transformation done step by step?
PS Or there are no explicit lines here, so '+' starts the conversion to a number, i.e.
undefined + 1 = Number(undefined) + 1 = NaN + 1 = NaN
So?
Answer the question
In order to leave comments, you need to log in
www.ecma-international.org/ecma-262/6.0/#sec-addit...
TLDR: in this particular case both operands are cast to a number. ToNumber(undefined) = NaN. NaN + 1 = NaN.
Because those are the specifications of the language. Here is the full table: https://dorey.github.io/JavaScript-Equality-Table/
And don't duplicate questions, please - read the language specifications, everything is there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question