Thursday, October 25, 2007

Debug JavaScript

Most of the time developers uses alert('message'); to debug the JavaScript. But its not that much efficient because whenever you want to change the property of an object you have to change the code & re-run the application.

One keyword available in JavaScript which will enable us to debug the JavaScript as we do in our .Net (will have intellisense), by this we can see all the properties & function available in the object.

Steps to Debug JavaScript:

  1. Identify the debugging point & place 'debugger;' keyword in the JavaScript code.
  2. Open IE (Internet Explorer) - Go to Tools -->Internet Options -->Advanced Tab
  3. Deselect the below mentioned two check boxes.
    • Disable script debugging (Internet Explorer)
    • Disable script debugging (Other)Debug Javascript - IE Settings
  4. Run the application (for which you want to debug). If you are developing .Net application Visual Studio .Net IDE will automatically jumps to debugger position. Start using the intellisense & resolve you issues.Debug Javascript
  5. If you are not using Visual Studio IDE, one window will prompt to select debugger engine with all available JavaScript debugger engines in you system. Some times even Visual Studio IDE will also prompt for the debugger.Debug Javascript - Select Debug Engine
  6. Select any of the Debugger engine and start debugging the JavaScript.

No comments: