Convert.ToString();

Debugging Javascript

You can do some pretty cool stuff with JavaScript, but with these pretty cool things comes something that can be a real pain to debug. JavaScript debugging in VS has come a long way and I think it is really impressive, but what if you are building a webpart for SharePoint which has JavaScript files deployed in the Layouts folder, what then smart guy?! Well last week under this very same senario I discovered the debugger; statement for JavaScript. Just place this statement anywhere is your Javascript, make sure to enable JavaScript debugging in your browser and then hit the page that uses your code. Once your browser hits this line you will be prompted to select a debugging tool and,  if you selected VS2005, your JavaScript file will be opened up and you will have a break point waiting patiently for you to figure out why you cannot divide 10 by 0 (see sample below).
<script type="text/javascript">
function doStuff(myparam)
{
debugger;
var i = "";
i = 10 / 0;
}
script>




© 2006 Convert.ToString(); | Blogger Templates by GeckoandFly.
No part of the content or the blog may be reproduced without prior written permission.