Will use of the debugging feature console.log reduce JavaScript execution performance? Will it affect the speed of script execution in production environments?
The performance hit will be minimal, however in older browsers it will cause JavaScript errors if the users browsers console is not open log is not a function of undefined. This means all JavaScript code after the console.log call will not execute.
You can create a wrapper to check if window.console is a valid object, and then call console.log in the wrapper. Something simple like this would work:
window.log = (function(console) {
var canLog = !!console;
return function(txt) {
if(canLog) console.log('log: ' + txt);
};
})(window.console);
log('my message'); //log: my message
Here is a fiddle: http://jsfiddle.net/enDDV/