Search code examples
javascriptdebuggingloggingproduction

Bad idea to leave "console.log()" calls in your production JavaScript code?


I have a bunch of console.log() calls in my JavaScript.

Should I comment them out before I deploy to production?

I'd like to just leave them there, so I don't have to go to the trouble of re-adding the comments later on if I need to do any more debugging. Is this a bad idea?


Solution

  • It will cause Javascript errors, terminating the execution of the block of Javascript containing the error.

    You could, however, define a dummy function that's a no-op when Firebug is not active:

    if(typeof console === "undefined") {
        console = { log: function() { } };
    }
    

    If you use any methods other than log, you would need to stub out those as well.