<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ankur</title>
    <description>The latest articles on DEV Community by Ankur (@ankurrai2602).</description>
    <link>https://dev.to/ankurrai2602</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F139593%2F4a6e6915-a064-4333-8e72-e19742b98fc2.png</url>
      <title>DEV Community: Ankur</title>
      <link>https://dev.to/ankurrai2602</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankurrai2602"/>
    <language>en</language>
    <item>
      <title>How to Debug Javascript Code</title>
      <dc:creator>Ankur</dc:creator>
      <pubDate>Sat, 23 Feb 2019 12:10:59 +0000</pubDate>
      <link>https://dev.to/ankurrai2602/how-to-debug-javascript-code-3fp4</link>
      <guid>https://dev.to/ankurrai2602/how-to-debug-javascript-code-3fp4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Javascript code Debugging tips.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method 1&lt;/strong&gt;: Stop execution control by putting the break point&lt;/p&gt;

&lt;p&gt;use the "debugger" statement to create breakpoint and use F12 key to open console window on chrome browser;&lt;/p&gt;

&lt;p&gt;example &lt;/p&gt;

&lt;p&gt;function addIt(x,y){&lt;br&gt;
    debugger;&lt;br&gt;
    return x + y;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method 2&lt;/strong&gt;: Open console window of chrome browser (you can use shortcut key F12)&lt;/p&gt;

&lt;p&gt;Click on source tab then Press Ctrl + P shortcut Key &lt;br&gt;
type the script file name which you want to debug.&lt;br&gt;
After opening a file you can put the breakpoint, it will be there until you removed it or disable it for your next run also.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method 3&lt;/strong&gt;: Modify the javascript code while debugging. just put breakpoint once execution control reaches on your breakpoint edit the code and press ctrl+s.&lt;br&gt;
You will find that execution start again of that block once you saved it by ctrl+S.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method 4&lt;/strong&gt;: use console.log statement to check the variable value and debugging purpose. &lt;br&gt;
console.log("********var1 = ",var1,"var2",var2);&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method 5&lt;/strong&gt;: use console.time() and console.timeEnd() to get the execution time of a block of script.&lt;/p&gt;

&lt;p&gt;//Example&lt;br&gt;
 function myFun(){&lt;br&gt;
    console.time();&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//your function code here...
//...........

console.timeEnd();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
you can also give a label to time function if you are using multipal console.time()&lt;/p&gt;

&lt;p&gt;//Example&lt;br&gt;
 function myFun(){&lt;br&gt;
    console.time('myFunLbl1');&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//your function code here...
//...........

//after some line you use
 console.time('myFunLbl2');
//.........
 console.time('myFunLbl2');
//.......
console.timeEnd('myFunLbl1');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
