Can I write the if else
shorthand without the else
?
var x=1;
x==2 ? dosomething() : doNothingButContinueCode();
I've noticed putting null
for the else works (but I have no idea why or if that's a good idea).
Edit: Some of you seem bemused why I'd bother trying this. Rest assured it's purely out of curiosity. I like messing around with JavaScript.
var | var
syntax. Careful as it's potentially difficult to "see", especially (IMO) ternaries being problematic. Use sparingly.:)
foo = bar | cat;
, where if the first is false? null?, it "falls through" to the second. I've only seen it, though, and don't use it.a || b
ora && b
, otherwiseb
will always be evaluated.