A few simple ways to debug Javascript code

Beyond alert() boxes, here a few very simple ways to debug your javascript code in an Ajax app:

1. Log messages within your js code.
In your html page where js code is running, define perhaps a div for keeping a log of messages that you can append to in your js code, then you can insert this line anywhere in your code, e.g:

$(‘log’).innerHTML += “User entered ” + sUserInput;

Then you can easily show or hide the log by applying a css style to the div tag.

2. Use a logging library, such as Lumberjack or log4js.

3. Venkman debugger

Leave a Reply