I recently had the need to add logging to a real-time application using JavaScript.
Most developers usually throw in console.log or alerts during development. But if the consoles/alerts are not removed before code goes to production or a client, it can cause a big problem.
The following code example using console.warn provides this safely. If window.console or console.warn are not supported, no message is generated. But it does not cause the page to choke, like using a simple console.log.
I’ve chosen console.warn here, but you can use console.info, etc. I suggest you test it thoroughly before deploying to any live application.
window.console && console.warn('Warning: someVariable does not exist');
See the full working example here.
Tested in:
jQuery version 1.7.2
FF 3.6+, Safari, Chrome, IE8+
iOS
Great books are available on JavaScript here.
Pingback: Banner ad animation with jQuery | The Blog of Clarke Ulmer