title: Removing console.log with closure compiler
body: <p>I'd like to make my JS code production ready by stripping out all <code>console.log("blah blah")</code> debugging statements. I'm confused by <a href="https://stackoverflow.com/questions/2934509/exclude-debug-javascript-code-during-minification#answer-5969752">this popular SO answer (code below)</a> on how to do this using <a href="https://developers.google.com/closure/compiler/" rel="noreferrer">Google's closure compiler</a>, a popular JS minifier/compiler.</p>
  
  <pre><code>/** @const */
  var LOG = false;
  ...
  LOG &amp;&amp; log('hello world !'); // compiler will remove this line
  ...
  
  //this will even work with `SIMPLE_OPTIMALIZATIONS` and no `--define=` is necessary !
  </code></pre>
  
  <p><strong>Two questions:</strong></p>
  
  <ol>
  <li><p><em>Multiples files:</em> How does the above code work with multiple files (basic example below)? It has to be in a closure, right? Doesn't this then mean you have to put this code on each page? Also, doesn't it also then mean you have to change all the variables you want to be global from <code>var foo='bar'</code> to <code>var window.foo='bar';</code> inside these closures on each page? </p></li>
  <li><p>Minor issue: Shouldn't it be <code>console.log('...')</code> rather than <code>log('...')</code> because <code>log()</code> gives an error? Am I missing something obvious here?</p></li>
  </ol>
  
  <p><code>
      &lt;script src='/assets/js/file1.js'&gt;&lt;/script&gt;
      &lt;script src='/assets/js/file2.js'&gt;&lt;/script&gt;
  </code></p>
  
  <p>contents of file1.js:</p>
  
  <pre><code>var foo='bar';
  console.log("foo"+foo);
  </code></pre>
  
  <p>contents of file2.js</p>
  
  <pre><code>var baz='bazzy';
  console.log("baz"+baz);
  </code></pre>