title: How does Closure Compiler use type information to compile to faster JavaScript?
body: <p>Google's <a href="https://developers.google.com/closure/compiler/" rel="nofollow">Closure Compiler</a> compiles to more efficient JavaScript. I can imagine a few simple examples, such as Closure Compiler reducing the call stack by calling functions directly or replacing constants with literals. But the <a href="https://developers.google.com/closure/compiler/docs/js-for-compiler" rel="nofollow">documentation</a> goes further, saying,</p>
  
  <blockquote>
    <p>"The Closure Compiler can use data type information about JavaScript
    variables to provide enhanced optimization and warnings."</p>
  </blockquote>
  
  <p>My understanding was that typed languages had two benefits: 1) type checking can catch errors during compilation--I can see how Closure Compiler could simulate this behavior--and 2) the program actually executes faster because it is compiled to another language (say Java to Java bytecode). With Closure Compiler, the output is still JavaScript. How can it be optimized based on type information?</p>