title: How to set default boolean values in JavaScript?
body: <p>Setting default optional values in JavaScript is usually done via the <code>||</code> character</p>
  
  <pre><code>var Car = function(color) {
    this.color = color || 'blue';
  };
  
  var myCar = new Car();
  console.log(myCar.color); // 'blue'
  
  var myOtherCar = new Car('yellow');
  console.log(myOtherCar.color); // 'yellow'
  </code></pre>
  
  <p>That works because <code>color</code> is <code>undefined</code> and <code>undefined || String</code> is always the <code>String</code>. Of course that also works the other way around <code>String || undefined</code> is <code>String</code>. When two <code>Strings</code> are present the first one wins <code>'this' || 'that'</code> is <code>'this'</code>. It does NOT work the other way around as <code>'that' || 'this'</code> is <code>'that'</code>.</p>
  
  <p>The question is: How can I achieve the same with boolean values?</p>
  
  <p>Take the following example</p>
  
  <pre><code>var Car = function(hasWheels) {
    this.hasWheels = hasWheels || true;
  }
  
  var myCar = new Car();
  console.log(myCar.hasWheels); // true
  
  var myOtherCar = new Car(false)
  console.log(myOtherCar.hasWheels); // ALSO true !!!!!!
  </code></pre>
  
  <p>For <code>myCar</code> it works because <code>undefined || true</code> is <code>true</code> but as you can see it does NOT work for <code>myOtherCar</code> because <code>false || true</code> is <code>true</code>. Changing the order doesn't help as <code>true || false</code> is still <code>true</code>.</p>
  
  <p>Therefore, am I missing something here or is the following the only way to set the default value?</p>
  
  <pre><code>this.hasWheels = (hasWheels === false) ? false: true
  </code></pre>
  
  <p>Cheers!</p>