Preventing console.log Undefined Errors
I don’t think it’s a good idea to leave
console.log
statements in production code, it’s a good idea to prevent your site from breaking if you accidentally do. I include this condition in the first script that loads on the page of most of my projects
if (typeof console == "undefined") {
window.console = {
log: function () {}
};
}
This JavaScript simply defines an empty function if the console is not available in the browser so stray log statements don’t break production for your valuable customers.