Skip to content

Instantly share code, notes, and snippets.

@Pindar
Created March 3, 2012 20:48
Show Gist options
  • Save Pindar/1968137 to your computer and use it in GitHub Desktop.
Save Pindar/1968137 to your computer and use it in GitHub Desktop.
JavaScript use of && to prevent errors caused by undefined variables.
var foo = {
t: {
s: function () {
console.log("bar");
}
}
},
bar = foo && foo.t && foo.t.s;
if (bar) {
bar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment