Skip to content

Instantly share code, notes, and snippets.

@johncmunson
Last active September 27, 2019 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncmunson/aad81ed6f03e3da39ade3d3aa5a894f4 to your computer and use it in GitHub Desktop.
Save johncmunson/aad81ed6f03e3da39ade3d3aa5a894f4 to your computer and use it in GitHub Desktop.
// Sometimes we do cool stuff like this...
let tacoType = hasQueso ? 'supreme' : 'normal'
// Or this in our markup...
`ng-class="isActive && 'md-primary'"`
// Or this to set default values...
this.color = config.color || 'blue'
// Sometimes though we'd like to have more
// options at our disposal when conditionally
// assigning to a variable.
// Enter the nested ternary. With some proper formatting,
// it actually reads quite nicely.
let dogSize = breed === 'rottweiler' ? 'big' :
breed === 'boxer' ? 'medium' :
breed === 'pug' ? 'small' :
'medium' // default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment