isNaN return a number as false


#1
  1. More on Control Flow in JS
  2. If / else if / else
    isNan

My code returns false (isNaN)

2
"Its not a number"

var number = Math.floor(Math.random() * 2 + 1);
console.log(number);


var isEven = function(number) {

  // Your code goes here!
  if (number % 2) {
    return false;
  } 
  
  else if ( isNaN(number) ) {
      return "Its not a number";
  } 
  
  else {
    return true;
  }
  
};

isEven();

#2

What error do you receive?


#3

It's just because I didnt undertand why I used inNaN in this script. There is no error at all. But, thank you.


#4

The isNaN() function determines whether a value is an illegal number (Not-a-Number).


#5

isNan() will return true, if the value is not a number

for example :

var value = "hello";
if(isNaN(value)) {
//this will be executed
} else{
//this will not executed except you change variable value to number
}


#6

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