title: Is there a null-coalescing (Elvis) operator or safe navigation operator in javascript?
body: <p>I'll explain by example:</p>
  
  <p>Elvis Operator (?: )</p>
  
  <blockquote>
    <p>The "Elvis operator" is a shortening
    of Java's ternary operator. One
    instance of where this is handy is for
    returning a 'sensible default' value
    if an expression resolves to false or
    null. A simple example might look like
    this:</p>
  </blockquote>
  
  <pre><code>def gender = user.male ? "male" : "female"  //traditional ternary operator usage
  
  def displayName = user.name ?: "Anonymous"  //more compact Elvis operator
  </code></pre>
  
  <blockquote>
    <p>Safe Navigation Operator (?.)</p>
    
    <p>The Safe Navigation operator is used
    to avoid a NullPointerException.
    Typically when you have a reference to
    an object you might need to verify
    that it is not null before accessing
    methods or properties of the object.
    To avoid this, the safe navigation
    operator will simply return null
    instead of throwing an exception, like
    so:</p>
  </blockquote>
  
  <pre><code>def user = User.find( "admin" )           //this might be null if 'admin' does not exist
  def streetName = user?.address?.street    //streetName will be null if user or user.address is null - no NPE thrown
  </code></pre>