Debugging Javascript in Visual Studio

Source: Internet
Author: User

In the previous article, we described how to debug JavaScript code in IE, which is primarily about debugging JavaScript in Visual Studio.

JavaScript debugging is divided into active debugging and passive debugging, active debugging refers to the developer in the code to start debugging, and add breakpoints to monitor the execution of the code, and passive debugging refers to the error in the code, the browser automatically into the debugging state, developers can do code debugging work.

IE Browser does not turn on passive debugging by default, we need to turn on the passive debugging function, in Internet Options:

Uncheck these two items so that the browser can enter the debug state passively when the code goes wrong.

To see this, we deliberately add an error to the code, and when the browser executes the error, it goes into the debug state:

The code is as follows:

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>    <title>Debug Page</title>    <Scripttype= "Text/javascript">        functionBtn_click () {vara= 1; varb= "2"; varC=a+b+D;        alert (c); }    </Script></Head><Body>    <inputtype= "button"value= "OK"onclick= "Btn_click ()" /></Body></HTML>

Obviously, the variable d is not defined and is used directly, which is an error. When we click on the "OK" button:

The browser pops up an error like this, if we are going to debug, click "Yes":

This time the Debug window is opened.

Perhaps you ask, what does this have to do with this content? Yes, this article is about debugging JavaScript code in Visual Studio, but enabling JavaScript debugging in IE is a requirement.

You may not notice that there are two options in the error window of IE pop-up:

Just went directly to the debug window because we checked the second option and debugged JavaScript directly in IE. If we tick out this option and then click the button "Yes":

The open window is where we choose to debug, you can debug in a Visual studio window that is already open, you can debug in a new window, and we choose to debug in new instance Microsoft Visual Studio 2012:

Click on the "Break" button:

This goes into Visual Studio for debugging. In addition, if we want to debug in a certain location, we can also add the debugger statement in the code, the browser will also let us choose where to debug the code:

function Btn_click () {    var a = 1;     var b = "2";     Debugger    var c = a + b;        alert (c);}

We have made some changes in the JS just now, removed the wrong variable d, and added the debugger statement, run to see the effect:

The browser pops up the window that selects the debugger, and the rest of the steps are the same.

Debugging Javascript in Visual Studio

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.