JavaScript/Notes/Debugging

From Noisebridge
Jump to: navigation, search

Contents

[edit] Tasks Page

Find a few tasks on the following page: debugging tasks

[edit] Error Reporting in IE

In IE, go to Tools > Internet Options and choose the Advanced tab. Make sure the check box for "Display a notification for every script error” is checked.

[edit] It Doesn't Work!

[edit] How to Launch the Debugger

Mac: Opera, Chrome, Firefox: Option + command + i.

Chrome: Debugging JavaScript

[edit] debugger keyword

function myFunc(myParam) {
  debugger;
  var myVar = 1;
 
  function innerFunc() {
 
  }
}


[edit] FIXME: Find and fix the bug

The code example below must be changed to output:

Check the value of i: 0
Check the value of i: 1
Check the value of i: 2
Check the value of i: 3

Example

var count = 0; 
var output = document.getElementById("output");
 
for ( var i = 0; i < 4; i++ ) { 
  setTimeout(function(){ 
    output.textContent = "Check the value of i:" + i; 
  }, 200); 
}

[edit] debugger from the menu

Firefox: Debugger.png

[edit] Add a Breakpoint

A breakpoint is an intentional point in a script put in place for debugging purposes. Opera: Firefox: Debugger-breakpoint.png


[edit] Debugger Keyword Full Example

Copy'n'paste this example into your text editor, open your browser, and open this file.

<!doctype html>
<head>
<title>Debugger Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h1>Test Debugger</h1>
<p>
When Entering an Execution Context, the Variable Environment is initialized with parameter 
variables, Function Declarations, and Variable Statements.
</p>
 
<pre>
function myFunc(myParam) {
  debugger;
  var myVar = 1;
 
  function innerFunc() {
 
  }
}
</pre>
 
<script>
function myFunc(myParam) {
  debugger;
  var myVar = 1;
 
  function innerFunc() {
 
  }
}
</script>
<p>Open the debugger and then click the button below.</p>
<button onclick="myFunc(7)">myFunc(7)</button>
</body>
</html>
Personal tools