Created
September 8, 2013 20:27
-
-
Save mojaray2k/6488119 to your computer and use it in GitHub Desktop.
The JavaScript logical AND operator doesn't evaluate the second expression if the first is false. You can use this
to your advantage and save yourself from having to write a full if-statement:
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
// Instead of writing this: | |
if ($('#elem').length) { | |
// do something | |
} | |
// You can write this: | |
$('#elem').length && alert("doing something"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment