Title
Debugging JavaScript
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
You can see line number, there you can set breakpoints, then press Shift + F5 to start debugging, and press F5 to proceed.
As you can see value of ‘c’ is undefined, but when you parse this step value of ‘c’ is updated to 9.
You can use same procedure in Internet explorer as well