Fix Uncaught ReferenceError
<p>What is a general solution to fix <strong><code>Uncaught ReferenceError</code></strong>.</p>

<p>I am creating a function to ensure debugging code goes into production. But there may be cases where a variable doesn't exist but the debugging code still exists. In such case it shouldn't halts the js. </p>

<pre><code>function debug(data, type){
    if(type == 'alert' &amp;&amp; mode !== 'production'){
      alert(data);
    }
    else if(type == 'halt' &amp;&amp; mode !== 'production'){
      debugger;
    }
    else{
      console.debug(data);
    }
}

debug(xyz) //xyz doesn't exists
</code></pre>
