Debugging with JavaScript is easy now in VS2005. Let’s start with a simple example.
Prerequisite for JavaScript Debugging:
Go to tools -> Internet Options -> Advance tab
Please note that these settings for IE 7 and can vary for other versions of IE.
Uncheck the Disable Script Debugging (Internet Explorer)
And Uncheck the Disable Script Debugging (Other)
And for Microsoft VM
Uncheck Java console enabled
Uncheck logging enabled
Check JIT compiler for virtual machine enabled
Lets create a JavaScript function and start debugging/Unit testing
So we have a JavaScript function:
<html>
<head>
<script language="javascript" type="text/javascript">
function jFunction()
{
debugger;
var str1 = "How to do Unit Testing ";
var str2 = "How to use Debugger in JavaScript ";
alert(str1);
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<asp:button runat="server" text="Button" OnClientClick="jFunction()" />
</form>
</body>
</html>
debugger is kind of breakpoint in JavaScript and when this function will execute our execution pointer will stop here. Alert() is used to display message in alert box.
Just run your web application by pressing the F5 button from keyboard.
Click on the Button.
A debugging window is opened and execution stops at debugger;
These are debugging buttons used to debug the code.
Step Into: It is used to send the execution, inside the function code.
Step Over: it execute the current statement and send execution pointer to next statement.
Step out: it send execution pointer to out of function and execute all function code.
So as the execution goes on , at any point of time you can check the intermediary values of variables by mouse over the variable or right click the variable - > Quick watch
0 comments:
Post a Comment