3

This is my usual way to debug javascript. Include alert(0); to break the flow and find out what is happening.

sometimes when i need multiple check points i do

alert('the flow is now in function 1');
alert('the flow is now in function 2');

or sometimes just

alert('success');

i would like to know if there is any standard way for debugging adopted as i am finding my current method very intrusive.

thanks in advance..:)

4 Answers 4

4

you might want to use the console... eg within firebug

otherwise you can use debugger; to break the script and force some debugger, or set breakpoints inside firebug (demo)

Sign up to request clarification or add additional context in comments.

3 Comments

can i also know if there is a way to monitor variable values in firebug.?
just hover the variables while debugging and you get their value... but you can also set watches
Yes, download it and get to know it well. It will become your best friend :)
1

Firebug in Firefox is the best, but IE8 also has a pretty good javascript debugger. You can set breakpoints and step through your code to follow the program flow and view variable information, etc...

3 Comments

can you suggest a debugger for IE where i can set break points..?
bundled with IE8: developer tools. otherwise IE developer toolbar: microsoft.com/downloads/…
IE8 has a built in javascript debugger. Go To Tools->Developer Tools and you can access the debugger through that utility.
0

If you prefer logging to using a debugger and need something that works in all browsers, I'd recommend my log4javascript.

Comments

0

Incorporating exception handling into your code could also be helpful.

Exception Handling in JavaScript

And a simple technique for accessing values for simple value checking would be to clear the address bar of the browser

("standard debugging way for javascript/jquery") and replacing it with:
javascript:alert(document.getElementById('comments-2521535').innerHTML);

and press enter to run the snippet on the page. It works a lot like the console in Firebug.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.