Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Before JavaScript debuggers were readily available, developers had to use creative methods to debug their code. This led to the placement of code specifically designed to output debugging information in one or more ways. The most common debugging technique was to insert alerts throughout the code in question, which was both tedious, because it required cleanup after the code was debugged, and annoying if an alert was mistakenly left in code that was used in a production environment. Alerts are no longer recommended for debugging purposes, because several other, more elegant solutions are available.
Logging Messages to a Console
Internet Explorer 8+, Firefox, Opera, Chrome, and Safari all have JavaScript consoles that can be used to view JavaScript errors. All three also allow you to write directly to the console from code. For this to work in Firefox 3.6 or earlier, you need to have Firebug installed (www.getfirebug.com), since it’s the Firebug console that is used in Firefox. Internet Explorer 8+, Firefox, Chrome, Safari, and Opera 10.5 allow you to write to the JavaScript console via the console object, which has the following methods: