JavaScript/Notes/Debugging

From Noisebridge Wiki
Revision as of 04:45, 10 February 2026 by Maintenance script (talk | contribs) (Imported from Noisebridge wiki backup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Tasks Page[edit]

Find a few tasks on the following page: debugging tasks

Error Reporting in IE[edit]

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.

It Doesn't Work![edit]

How to Launch the Debugger[edit]

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

Chrome: Debugging JavaScript

debugger keyword[edit]

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


FIXME: Find and fix the bug[edit]

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); 
}

debugger from the menu[edit]

Firefox: File:Debugger.png

Add a Breakpoint[edit]

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


Debugger Keyword Full Example[edit]

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>