Skip to content

Instantly share code, notes, and snippets.

@evansdiy
Created May 31, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansdiy/458da71dbfb364d10e92534d5412b4f2 to your computer and use it in GitHub Desktop.
Save evansdiy/458da71dbfb364d10e92534d5412b4f2 to your computer and use it in GitHub Desktop.
check num is odd or even
function isEven(num) {
return (num & 1) === 0;
}
@evansdiy
Copy link
Author

evansdiy commented May 31, 2016

if the num is even then the last bit of it should be 0, so the bitwise and operator return 0. 0 === 0, is't even.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment