Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 296
justjoe Avatar asked Aug 28 '10 07:08

justjoe


People also ask

Is there a way to debug JavaScript?

But fortunately, all modern browsers have a built-in JavaScript debugger. Built-in debuggers can be turned on and off, forcing errors to be reported to the user. With a debugger, you can also set breakpoints (places where code execution can be stopped), and examine variables while the code is executing.

How do I debug JavaScript script?

Javascript provides the keyword Debugger to debug the code. When we add the debugger keyword in between our code, so after executing the code, a debugger panel will show up where we can make breakpoints and play/pause to check the value and understand according to it.


2 Answers

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

like image 178
Yi Jiang Avatar answered Oct 02 '22 14:10

Yi Jiang


firebug or similar browser plugins

like image 28
Adam Butler Avatar answered Oct 02 '22 15:10

Adam Butler