I thought '88', '89', 'blabla' are strings. Was I wrong?


var isEven = function(number) {
    if (number % 2 === 0) {
        return true;  
    } else if (isNaN(number)) {
        return 'This is not a number!';
    } else {
        return false;

return false (and if isEven(89) )

return true (and if isEven(88) )

return 'This is not a number!'

I thought '88', '89', 'blabla' are strings. Was I wrong? Please help me to understand this moment.


When we pass any value to isNan(), It first coerced into a number If it can be coerced then the resulitng value is checked if its a number of not.

as "67" coerced into 67..
isNan() sees it as a number and returns false.

Check these Articles..

isNan() confusion

also check this good article on Coercion
Tutsplus - Coercion


Thank you! But if I don't want isNan() coerced "67" into 67.. What can I do? Nothing? It's a really strange situation...


Yes,Its one of the aspect of the language introduced by designer which is confusing.
I'd suggest to go with MDN documentation.(Its updated frequently and there are tons of examples)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.