Skip to content

Instantly share code, notes, and snippets.

@dylanjha
Last active December 16, 2015 09:48
Show Gist options
  • Save dylanjha/5415410 to your computer and use it in GitHub Desktop.
Save dylanjha/5415410 to your computer and use it in GitHub Desktop.
cheap way to do a conditional in javascript. If the first part returns a falsy value, the second part doesn't execute
(function(){
o = {}
o.a = 1
o.a == 1 && console.log("o is one:", o.a)
o.a == 2 && console.log("false, this won't run")
o.b && console.log("undefined is falsy, this wont run")
//it's a little nicer than wrapping if{ } statements:
if(o.a == 1) { console.log("o is one:", o.a) }
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment