Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Created September 8, 2013 20:27
Show Gist options
  • Save mojaray2k/6488119 to your computer and use it in GitHub Desktop.
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:
// 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