title: JavaScript - Check if a variable is a number : typeof doesnt work, isNaN does
body: <p>I currently face a problem, it may be very simple but I found nothing in my research...</p>
  
  <p>I want to check (in JavaScript) that a variable is a number, and if it is higher than 100 or lower than 0.</p>
  
  <p>I tried this :</p>
  
  <pre><code>if ((returnValue &gt; 100) || (returnValue &lt; 0) || (typeof returnValue != 'number')) { 
      //not correct
  } else {
   // let's do some stuff here
  }
  </code></pre>
  
  <p>But it doesn't work... When I put for example the number 50 (which is good), happening in the "if" and not in the "else" as expected ! </p>
  
  <p>So I did :</p>
  
  <pre><code>if ((returnValue &gt; 100) || (returnValue &lt; 0) || (isNaN(returnValue)))
  </code></pre>
  
  <p>and then I noticed that it perfectly worked !</p>
  
  <p>I know too I could split that in two parts , firstly testing if the variable is a number and then if it is greater than 100 or less than 0, but this is not what I am currently looking for ;)   </p>
  
  <p>Could you please explain me why the first try doesn't work (and/or make it work) ?</p>
  
  <p>Thanks !</p>