I currently have this JS statement everywhere in my code:
window.console && console.log("Foo");
I am wondering if this is costly at all, or has any negative side-effects in production.
Am I free to leave client-side logging in, or should it go?
EDIT: In the end, I suppose the best argument I (and anyone else?) can come up with is that there is a possibly non-negligible amount of extra data transferred between the server and the client by leaving logging messages left in. If production code is to be fully optimized, logging will have to be removed to reduce the size of javascript being sent to the client.
You should not add development tools to a production page.
To answer the other question: The code cannot have a negative side-effect:
window.consolewill evaluate to false ifconsoleis not definedconsole.log("Foo")will print the message to the console when it’s defined (provided that the page does not overwriteconsole.logby a non-function).