How to enable JavaScript debugging in visual studio 2019 or 2017


How Can I enable Javascript debugging in Chrome using Visual Studio 2017 or 2019? I have been using Visual Studio 2017, but I am not able to debug Javascript code by placing debug in the Visual Studio Javascript code.

So, how can I achieve it and check line by line output of the Javascript code? I have checked this article ("How to debug in visual studio? ( Tutorial to debug C# code )") but it shows debugging C# code in Visual Studio.


Asked by:- bhanu
0
: 2229 At:- 5/17/2021 3:58:55 PM
Javascript how to enable javascript debugging in visual studio 2019






1 Answers
profileImage Answered by:- vikas_jk

You can enable debugging on Javascript using "debugger" keyword in your Javascript code and then use the Chrome browser "console" area to debug the code.

You will actually see the output of each line of code, when you will hit "F10" to debug each line of JS code.

Suppose this is your Javascript code

            function Checkdebugger() {
                debugger;
                console.log("Function Called");
                var CheckValue = 1;
                var AnotherValue = 10 * 23;

                var Output = AnotherValue;

            }
         
            Checkdebugger();

Then you will see the output in chrome's console as below

/javascript-debugging-in-chrome-using-Visual-studio-min.gif

As you can see in the above output, your Web-Browser's Console should be open to Debug JS code.

Once the debugger is hit, you can press "F10" to check output of each line of code.

Another method

Go to Tools -> Options -> Debugging -> General and turn on the setting Enable JavaScript Debugging for ASP.NET (Chrome, Edge and IE).

Then once you will hit "F5".

Using above option you can now debug both JavaScript and TypeScript directly in Visual Studio when using Google Chrome or Edge as a browser.

You can see the below sample output when debugging JS in Visual Studio

javascript-debugging-using-visual-studio-min.png

 

1
At:- 5/17/2021 4:22:25 PM
Excellent answer thanks. 0
By : bhanu - at :- 5/26/2021 11:25:10 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use