title: ! operator in JavaScript
body: <p>I am now confused about ! operator in JavaScript. My understanding was ! operator operates only on boolean. But a comment to one of my <a href="https://stackoverflow.com/a/8876061/929701">answers</a> says it can operate on anything and returns a boolean, which happened to be true after I did some tests.</p>
  
  <pre><code>alert(!undefined); //true
  alert(!function(){}); //false
  alert(!{}); //false
  alert(!null); //true
  alert(!()); //crash
  alert(!"false"); //false
  alert(!false)​;​​​​​​​​​​​​ //true​​​​​​​​​​​​​​​​​​
  </code></pre>
  
  <p>Can somebody help me generalize the behavior of ! operator.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Even more confusing stuff:</p>
  
  <pre><code>​alert( new String() == ""); //true
  alert(!""); //true
  alert(! new String()); //false
  </code></pre>
  
  <p>How?
  ​</p>