views:

122

answers:

7

the only thing i know how to javascipt is using alert(). is there any other way to help debugging javascript ?

+3  A: 

firebug or similar browser plugins

Adam Butler
+6  A: 

Using Firebug, and the web development tools on other browsers, you can use commands such as

console.log(myVar);

to watch for variables, instead of the more disruptive alert. With the consoles on most development tools, you can also run arbitrary pieces of Javascript from there without having to modify the actual code, which can help immensely with with debugging Javascript. Oh, and the break on error function helps too.


When you open up Firebug you see something like this. Click on the console tab and enable it:

alt text

Enter your code after the >>>. Just for fun try something like $('body').css('-moz-transform', 'rotate(10deg)') :D

Yi Jiang
where i should input this command ?
justjoe
@justjoe The `console.log()` function can be used as a replacement for `alert` meaning that everywhere `alert` can be used, log also can. You must have the console open to see the logs, of course.
Yi Jiang
+2  A: 

Most modern browsers have such capabilities already inside or with some extra plugins:

These are all free tools available to you and work great when profiling/debugging javascript.

XIII
+1  A: 

If you can't use any of these browser tools (for whatever reason, maybe mobile development?), you could also attach YUI Logger to your page, which pops up a debugging console you can write to: http://developer.yahoo.com/yui/logger/

halans
+1  A: 

Firebug is the favorite option when debugging Javascript.
However another alternative often missing from the answers, Opera Dragonfly, is worth the try.

Opera is one of the most compliant browser (to standards), and its debugging tools are not only nice, they're also very powerful. Opera is free.

ring0
+1  A: 

The Safari and Chrome developer tools are excellent

slomojo
+1  A: 

There are various logging tools available, including my own log4javascript, which works on all major browsers.

Tim Down