When the following line of code is executed in node.js console the result is:
var string = 'abc'; string++;
// NaN
string;
// NaN
I thought that it should work like this:
var string = 'abc'; string++;
// 'abc';
string;
// NaN
My rationale:
Because
++
is a post-increment operator, meaning it returns the old value (in this caseabc
) and then it adds1
to the string, getsabc1
, which is Not A Number, but the++
operator should return a nubmer, so it returns specialNaN
number and assigns it to variable string
Please specify where I am wrong.