title: Testing for console.log statements in IE
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3326650/console-is-undefined-error-for-internet-explorer">&#39;console&#39; is undefined error for internet explorer</a>  </p>
  </blockquote>
  
  
  
  <p>If you have <code>console.log</code> statements in your code, Internet Explorer will throw a JavaScript error (at least in IE7 which is what our intranet users have installed).</p>
  
  <p>I am using Firefox for most of my development testing primarily because of the functionality provided by Firebug (where I use a lot of console statements) but I also need to test in IE.</p>
  
  <p>if I add the following to my JavaScript, the error does not get thrown.</p>
  
  <pre><code>var debugging = false;
  if (typeof console == "undefined") 
      var console = { log: function() {} };  
  </code></pre>
  
  <p>The problem is that I would like to trigger an event if debugging mode is false.  If I create a function to test whether debugging is false and do an action (at this point just an alert) but when I try do the following I receive an IE error saying <strong>Console is not defined</strong>.</p>
  
  <pre><code>var debugging = false; // or true   
  if (typeof console == "undefined") 
      var console = { log: function() {consoleMsg()} };   
  
  function consoleMsg() {
      if(!debugging) {
      alert('Console.log event in Production Code');
  }   
  </code></pre>
  
  <p>If someone could help me to fix my code, provide a better way to help me achieve my goal, or direct me to a resource to edumacate myself I would be very appreciative.</p>