I started from expression returning true
(I choose 1==1
) and wrote it in console
cosole.log(1==1);
It logs true
. Now I want to convert it to integer (1
) and wrap it in parseInt()
console.log(parseInt(1==1));
It logs NaN
. Looks like it is trying to convert 1==1
to string before it converts it to number.
Then I'll simply multiply 1==1
by 1.
console.log((1==1)*1);
It logs 1
.
Why in first case it converts it converts true
to string before converting it to integer (resulting NaN
) while I want to convert it to string and in the second case it converts true
directly to integer? I'd expect that true*1
will be NaN
too.