Tips, tricks and all the info about Microsoft Visual Studio 2008

Visual Studio 2008 JavaScript Debugging

, posted: 19-Mar-2008 09:00

Visual Studio has always offered an impressive debugging environment. From my first experiences with Visual Basic 3 I was hooked on being able to set break points and step through code.

Microsoft continued to improve the debugging experience and in Visual Studio 2008 they have added JavaScript debugging as a first class citizen.

This is great for modern web developers who are expected to roll out AJAX web sites that make heavy use of JavaScript. Previously debugging JavaScript was a case of pumping out alert boxes in code to display variable values – not an enjoyable way to debug by any stretch of the imagination!

So here is an overview of what to expect when debugging JavaScript with Visual Studio 2008.

Setting break points
Setting break points for debugging JavaScript is done in exactly the same manner as setting break points in your code. Clicking the gutter space at the start of the line you wish to break on will place a red dot and highlight the line. When this code is encountered the execution flow will pause at that spot.



Once a break point is hit the usual stepping functionality is available – step through and step into so you can watch the execution flow closely.

The break points that you set will be persistent and exist when you re-open a project where you previously set break points.

Variable evaluation
Resting over a variable while debugging with provide the normal inspection view allowing developers to dig deeper into variables. In this case we can see how long our JavaScript will take to perform a resize function.



Updating values on the fly
Often when debugging you will want to change a value, just to test how the system handles it. Rather than needing to stop, change and restart you can now update a value on the fly while debugging to test new values. In this case we can update our resize time to 25 seconds.



By clicking the value and typing in the new one we can instantly see this reflected. It couldn’t be easier.

Querying with the intermediate window
The intermediate window is a hidden gem in Visual Studio – it’s been there as long as I can recall but I don’t often see other developers making use of this powerful tool.

While debugging, jump into the intermediate window by clicking on the pane at the bottom of Visual Studio. If you don’t see the intermediate window you can bring it into view by pressing CTRL + ALT + I.

Within the intermediate window you can write queries and code that should be executed within the scope of the currently hit break point. This is great when needing to inspect values that are hard to navigate to, type cast and carry out other tasks.



A word for those who want to start debugging with Visual Studio 2008 right away – make sure that you enable script debugging in Internet Explorer. Without enabling it you will get an error about no symbols being loaded and the the break point will never be hit.



I will be the first to admit that I have never been the biggest fan of writing JavaScript – I’ve always felt the tooling support available was poor and I just plain hated trying to debug my scripts. It is great to see that Visual Studio 2008 adds JavaScript debugging. I’m sure there are many other developers like myself who are considerably more happy and comfortable working with JavaScript now.

Download Visual Studio 2008 90 day trial
For detailed information and to request a free 90-day trial DVD of Visual Studio 2008 Team Suite to be sent out to you, go to the Microsoft Visual Studio webpage.

About the Author

John-Daniel Trask is a co-founder of Mindscape, a product development company based in Wellington New Zealand. He also maintains a popular blog about software development and business.

Other related posts:
The Visual Studio 2008 blog is back
Windows Workflow Enhancements in Visual Studio 2008
A completely non-comprehensive introduction to Visual Studio 2008








Comment by Dave, on 4-Apr-2008 09:39

I've been debugging for a while with Visual Studio 2005 and one thing strikes me as odd. I have 2008 at home (XP) and at work (Vista) and at work I no longer see the "Scripts" window with all the loaded scripts. I can't seem to turn it back on. Also, the menu structure seems different from XP to Vista. Can you shed any light on this?


Comment by lynette, on 20-Nov-2009 10:33

i have enable in IE the ability to debug scripts. if i go to my section in my code and attempt to place a breakpoint i receive the message that this is an invalid location for a breakpoint. Am i missing something here? Thanks - Lynette Temple


About the Visual Studio 2008 Blog

In the years since the hugely successful release of Visual Studio 2005, Microsoft has used developer feedback from all over the world to introduce over 250 new features in the 2008 release.

This sponsored blog will bring Visual Studio 2008 tips and tricks from well known developers in the Australian and New Zealand tech community directly to you.

Make sure you bookmark this blog or subscribe to our RSS feed.



Other blog posts

The New Zealand ALM Conference...
Writing your own Html Helpers ...
Automating Visual Studio 2008...
Windows Azure Table Storage - ...
Windows Azure Table Storage - ...
XML and XSLT in Visual Studio ...
Introduction to New SQL Server...
Using the Visual Studio 2008 P...
Getting started with Windows A...
Why consider sitting for an MC...


Some recent comments

Praveen M on Visual Studio 2008 support for building SilverLigh: I installed SILVERLIGHT TOOLS for VS2008 at my work. I am able to do silverlight...

zefo on Unit testing with Visual Studio 2008: Just minor recommendation: better use *.png for the screenshots. Jpeg is more su...

gil ziny on Unit testing with Visual Studio 2008: When I associate the unit test with TFS testing policy, if fails during check-in...

lynette on Visual Studio 2008 JavaScript Debugging: i have enable in IE the ability to debug scripts. if i go to my section in my c...

Junkie on Why consider sitting for an MCTS or MCP Certificat: The way you presented the case for certification has been completely different f...

Brian Link on Unit testing with Visual Studio 2008: You seem to be incorrect in one of your opening remarks - it seems that web.conf...

Dipanwaya on Unit testing .Net Compact Framework applications w: Steps Behind the Test in the VS 2008? How to test a module in the VS 2008 Envir...

Ricardo on Visual Studio 2008 support for building SilverLigh: Yes! Found the solution myself :) Reset the environment of Visual Web Developer...

Ricardo on Visual Studio 2008 support for building SilverLigh: Have the same problem after installing Visual Web Developer 2008 SP1 and Silverl...

kjward on Automating Visual Studio 2008: thanks lots for all the great info. i'm sure the answer to my question is in th...



Disclaimer

The Visual Studio 2008 blog is sponsored by Microsoft NZ. The blog posts are the authors' genuine accounts of their experiences with Visual Studio 2008 and are not influenced or filtered by Microsoft NZ in any way.