1

I've got console.log statements all over the place in my JavaScript source files printing stuff out to the console that I don't want the user to see.

One way is to scan through all my JavaScript source files and remove the console.log statements.

But I was wondering if there was a way to have them in there but not execute them for production distributions. Is there a way to conditionally include them (or whatever you want) akin to C/C++/C# debug symbols?

#if DEBUG
  console.log("User IP Address: " + localStorage.getItem("userIP"));
#endif

I understand there's no way to distinguish between a production distro and a development one, and there are no binary symbols since there's no compilation of JavaScript to object files, but if the language were to include a special construct like #if <SYMBOL> with some pre-defined symbols, that would make life easier?

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336

0 Answers0