Skip to content

Instantly share code, notes, and snippets.

@tarasowski
Last active July 18, 2018 09:21
Show Gist options
  • Save tarasowski/84dea4cd1d216ef5be55e176e66c8aa8 to your computer and use it in GitHub Desktop.
Save tarasowski/84dea4cd1d216ef5be55e176e66c8aa8 to your computer and use it in GitHub Desktop.
#JavaScript - Short Circuit
let isVarAssigned = false
// if isVarAssigned is true, assign the value else assign 'There is no variable assigned' String
const x = isVarAssigned || 'There is no variable assigned'
console.log(x)
// if isVarAssigned is true go and assign the value 'Yes the variable is assigned' if false assign false
const y = isVarAssigned && 'Yes there is a variable assiged'
console.log(y)
// There is no variable assigned
// false
// good description why and how: http://www.openjs.com/articles/syntax/short_circuit_operators.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment