Excuse me, your console.log is breaking things
Its not a good idea to leave your debugging statements in your code. But it sometimes makes sense to have state/informational statements for quick verification on a production environment.
And sometimes we just plain forget to get rid of those pesky console.log statements.
Make a fallback to prevent JS errors when the console is not defined:
if( typeof console !== "undefined"){
console.log("The console is working");
} else {
console = {};
console.log = function(){};
console.dir = function(){};
console.info = function(){};
console.warn = function(){};
console.err = function(){};
console.error = function(){};
}
This way, if console is not available, it won't break scripts (mostly an issue in IE).
Or even better, adapt it to only use console.info, console.error in production environments.
Written by Peter Peterson
Related protips
1 Response
just run it before production branches merge
$ ack 'console.log' -r
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Debugging
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#