Easy javascript debugging with the debugger statement

by Fredrik Karlsson 1. July 2009 12:25

Debugging javascript has been a really tidious task, especially in Internet Explorer. And if you're an EPiServer developer, you will have to debug some javascript in IE. I recently stumbeld upon this very hand statement: "debugger". Apparently it's been around for ages but I haven't noticied it before, so I thought I would make a quick post about it.

Example

The code is really easy:

function MyJavascriptFunction()
{
var i = 0:
var j = i + 1;
debugger;
}

Result

In Internet Explorer you will get the normal "Do you wish to debug" dialog box and just select yes:

 



And you will be able to debug in Visual Studio:

 


And in firefox it will open up Firebug:

 

And as you can see, it keeps the context you are in, very handy indeed.

Conclusion

It's not the best way to debug javascript, but it's really easy and will probably be enough in almost all cases. So start using the debugger statement now

Read more

 http://msdn.microsoft.com/en-us/library/0bwt76sk(VS.85).aspx

Tags: , ,

Development

blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Sweden License.


Welcome to the Dropit blog!

Here we, the people that work at Dropit, will write about stuff that interests us. For example web development, especially with .NET and EPiServer - but we'll also talk about other techniques that interest us, marketing on the web, social phenomenons, pop culture, games and software development in general.