I would probably abuse the short-circuiting nature of JavaScript’s logical AND operator and replace instances of:
console.log("Foo.");
With:
DEBUG && console.log("Foo.");
Assuming DEBUG
is a global variable that evaluates to true
if debugging is enabled.
This strategy avoids neutering console.log()
, so you can still call it in release mode if you really have to (e.g. to trace an issue that doesn’t occur in debug mode).