Last active
December 16, 2015 09:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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