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' -rHave a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside