title: Ruby's ||= (or equals) in JavaScript?
body: <p>I love Ruby's <code>||=</code> mechanism. If a variable doesn't exist or is <code>nil</code>, then create it and set it equal to something:</p>
  
  <pre><code>amount # is nil
  amount ||= 0 # is 0
  amount ||= 5 # is 0
  </code></pre>
  
  <p>I need to do something similar in JavaScript now. What's the convention or proper way to do this? I know <code>||=</code> is not valid syntax. 2 obvious ways to handle it are:</p>
  
  <pre><code>window.myLib = window.myLib || {};
  
  // or
  
  if (!window.myLib)
    window.myLib = {};
  </code></pre>