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

You are viewing a single comment's thread from:

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

in utopian-io •  7 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
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for your advice