title: What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?
body: <p>The <em><a href="https://www.destroyallsoftware.com/talks/wat" rel="noreferrer">'Wat' talk for CodeMash 2012</a></em> basically points out a few bizarre quirks with Ruby and JavaScript.</p>
  
  <p>I have made a JSFiddle of the results at <a href="http://jsfiddle.net/fe479/9/" rel="noreferrer">http://jsfiddle.net/fe479/9/</a>.</p>
  
  <p>The behaviours specific to JavaScript (as I don't know Ruby) are listed below.</p>
  
  <p>I found in the JSFiddle that some of my results didn't correspond with those in the video, and I am not sure why. I am, however, curious to know how JavaScript is handling working behind the scenes in each case.</p>
  
  <pre><code>Empty Array + Empty Array
  [] + []
  result:
  &lt;Empty String&gt;
  </code></pre>
  
  <p>I am quite curious about the <code>+</code> operator when used with arrays in JavaScript.
  This matches the video's result.</p>
  
  <pre><code>Empty Array + Object
  [] + {}
  result:
  [Object]
  </code></pre>
  
  <p>This matches the video's result. What's going on here? Why is this an object. What does the <code>+</code> operator do?</p>
  
  <pre><code>Object + Empty Array
  {} + []
  result:
  [Object]
  </code></pre>
  
  <p>This doesn't match the video. The video suggests that the result is 0, whereas I get [Object].</p>
  
  <pre><code>Object + Object
  {} + {}
  result:
  [Object][Object]
  </code></pre>
  
  <p>This doesn't match the video either, and how does outputting a variable result in two objects? Maybe my JSFiddle is wrong.</p>
  
  <pre><code>Array(16).join("wat" - 1)
  result:
  NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
  </code></pre>
  
  <p>Doing wat + 1 results in <code>wat1wat1wat1wat1</code>...</p>
  
  <p>I suspect this is just straightforward behaviour that trying to subtract a number from a string results in NaN.</p>