Sudantha Sudantha - 1 year ago 98
Javascript Question

Will console.log reduce JavaScript execution performance?

Will use of the debugging feature

reduce JavaScript execution performance? Will it affect the speed of script execution in production environments?

Is there an approach to disable console logs in production environments from a single configuration location?

Answer Source

If you are going to have this on a public site or something, anyone with little knowledge on using the developer tools can read your debug messages. Depending on what you are logging, this may not be a desirable behavior.

One of the best approaches is to wrap the console.log in one of your methods, and where you can check for conditions and execute it. In a production build, you can avoid having these functions. This Stack Overflow question talks in details about how to do the same using the Closure compiler.

So, to answer your questions:

  1. Yes, it will reduce the speed negligible.
  2. But, don't have it as it's too easy for a person to read your logs.
  3. The answers to this question may give you hints on how to remove them from production.