Debugging JavaScript

Title

Debugging JavaScript

JavaScript Strict Mode - Part 1

 

 

 

 

 

 

 

Introduction

JavaScript code viagra pas cher often contains error, but it will give no error message or warnings and you will get no indication where to search for errors.

Searching errors in programming language is called code debugging. Code debugging is not an easy task, but modern browsers contain inbuilt code debuggers. These debuggers can be turned on and off, forcing errors to be reported to user. With a debugger you can put breakpoints (places where code execution has stopped), and examine variables while the code is still executing.

In order to access debugger in your browser just press F12 key, and select “console” in debugger menu.

In this post I’ll show how to debug in Chrome and Internet Explorer.

I’ll be using Visual Studio 2013 to for this code block.

Code Sample


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript - Strict Mode</title>
</head>
<body>
<script>
debugger;
var a, b, c;
a = 4; b = 5;
c = a + b;
var d = c / 0;
console.log(d);
</script>
</body>
</html>

How to access debugging tool.

By default in most of the browser you can access developer mode by pressing F12 key, in case it doesn’t works for you, below is the work around for same.

Google Chrome

  • First option is, go for Ctrl-Shift-I
  • Second,
  • Go to menu
  • Select tools
  • Developer tool
  • Finally select Console

Internet Explorer

  • Go to menu
  • Select tools
  • Developer tool
  • Finally select Console

img1

 

You can see line number, there you can set breakpoints, then press Shift + F5 to start debugging, and press F5 to proceed.

 

img2

 

As you can see value of ‘c’ is undefined, but when you parse this step value of ‘c’ is updated to 9.

 


img3

 

img4

 

 

You can use same procedure in Internet explorer as well

 

ie

 


JavaScript, ASP.Net & PHP Web Developer. Connect with me on Facebook and Twitter.

Share This Post

Related Articles

Powered by Paras Babbar · Designed by Paras Babbar