Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good techniques at debugging javascript? [closed]

So I use JavaScript fairly regularly and I was wondering if there were any good tips or tricks in debugging javascript....Like for example I have a good one I use fairly regularly.

In my code i would do something like this

window.p = $(this);

and in the console I can do my filtering like this

window.p.next("li").find("a").val();

or whatever i need to do...but this makes it easy to debug a specific spot in the code and I know there has got to me many tips and tricks out there....thanks in advance

Also i looked at this question and though its helpful i was looking more for techniques like my above ...

like image 654
Matt Elhotiby Avatar asked Aug 27 '26 06:08

Matt Elhotiby


1 Answers

I usually set a breakpoint and look at the Scope Variables, or add my own watch expressions or hover over the variables and just step through the code.

Sometimes I find it useful to just log things using console.log().

Other times, when things work, but they are too slow I use console.profile() and console.profileEnd()

A useful trick is the use of $0. If you have an element selected in the HTML pannel, you can reference it in the console as $0.

All techniques above work in Firefox+Firebug and Webkit based browsers (such as Chrome & Safari). Lately I prefer Chrome because it allows me to edit code inline (check this tutorial by Paul Irish)

For extra debugging help for jQuery I use FireQuery

like image 125
Dan Manastireanu Avatar answered Aug 29 '26 21:08

Dan Manastireanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!