Within the Developer tools, a Console panel exists for executing script statements on-the-fly. You can make use of Console methods to expose information that is flowing through your scripts. The console.log method can be used as an alternative to the obtrusive JavaScript alert method to track what's going on within your code without having to click OK for every dialog box that alert throws up. This will work only if you have the Console opened though.
So to remove your debugging code when you deploy to production, use this:
if ( window.console ) {
// console is available
}
While console.log is one of the more common methods supported in popular browsers(IE, Firefox Firebug, Chrome, Safari), there are other methods as well for which support may vary -
- console.info
- console.warn
- console.error
- console.assert
Ctrl+Shift+J shortcut lets you jump to the Console panel in Chrome.
0 comments:
Post a Comment