You are viewing a single comment's thread from:

RE: Basic Tutorial Javascript : Learn To Program To Determine Odd Number Or Even Number

in #utopian-io7 years ago

Remember JS evaluates numbers as booleans as C does, so the == 0 part in the if sentence is not needed. If you still want to use it, do it a triple equals (===) instead.

You can better write a simple function as:

function isOdd(n) {
  return n % 2;
}

isOdd(5)  // returns true
isOdd(4)  // returns false
Sort:  

Thank you for your advice