Skip to content

Instantly share code, notes, and snippets.

@brainfoolong
Created August 8, 2021 15:48
Show Gist options
  • Save brainfoolong/4c30bdf9d94acfa4d2f61f0ae932ef71 to your computer and use it in GitHub Desktop.
Save brainfoolong/4c30bdf9d94acfa4d2f61f0ae932ef71 to your computer and use it in GitHub Desktop.
BitMask Demo
let CUTE = 1
let ANGRY = 2
let HUNGRY = 4
let CAT = ANGRY | HUNGRY
// angry only would be: let CAT = ANGRY
// cute, angry and hungry would be: let CAT = CUTE | ANGRY | HUNGRY
if (CAT & HUNGRY) {
console.log('Yeah my cat is hungry')
if (CAT & ANGRY) {
console.log('And he\'s angry')
if (CAT & CUTE) {
console.log('But it doesn\'t matter because he\'s cute')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment