SlideShare a Scribd company logo
1 of 69
Download to read offline
RICHTIGES DEBUGGING IN
JAVASCRIPT
Wednesday, June 26, 13
WER BIN ICH?
• Sebastian Springer
• https://github.com/sspringer82
• @basti_springer
• Entwickler @ Mayflower
Wednesday, June 26, 13
AGENDA
• Warum Debugging?
• Welche Debugger gibt es?
• Wie funktioniert Debugging?
• WeiterführendeThemen
Wednesday, June 26, 13
WARUM DEBUGGING?
Wednesday, June 26, 13
WENN’S MAL SCHNELL
GEHEN MUSS
console.log($('[name="username"]').val());
alert($('[name="username"]').val());
Wednesday, June 26, 13
DER UNTERSCHIED?
Wednesday, June 26, 13
WENN’S MAL SCHNELL
GEHEN MUSS
console.log($('[name="username"]').val());
alert($('[name="username"]').val());
Gibt den Wert aus - das Script läuft weiter
Wednesday, June 26, 13
WENN’S MAL SCHNELL
GEHEN MUSS
console.log($('[name="username"]').val());
alert($('[name="username"]').val());
Gibt den Wert aus - und hält das Script an
Wednesday, June 26, 13
WAS HAT DAS JETZT MIT
DEBUGGING ZUTUN?
Wednesday, June 26, 13
FUNKTIONEN EINES
DEBUGGERS
• Steuerung des Programmablaufs - wie mit alert()
• Inspizieren von Daten - wie mit alert() und console.log()
• Modifizieren von Inhalten - Kombination aus alert() und
Konsole
Wednesday, June 26, 13
WARUM ALSO DEBUGGING
• Finden von Fehlern
• Anzeige der Umgebung zu einem Zeitpunkt
• Testen vonVerhalten bei veränderten Bedingungen
Wednesday, June 26, 13
WELCHE DEBUGGER GIBT ES?
Wednesday, June 26, 13
Wednesday, June 26, 13
FIREFOX
Wednesday, June 26, 13
FIREBUG
Wednesday, June 26, 13
CHROME
Wednesday, June 26, 13
INTERNET EXPLORER
Wednesday, June 26, 13
WIE FUNKTIONIERT
DEBUGGING?
Wednesday, June 26, 13
DEBUGGER STARTEN
Wednesday, June 26, 13
DEBUGGER STARTEN
$(document).ready(function () {
$('button').on('click', function () {
debugger;
var inputNumber = $('[type="number"]').val();
$('output').val(fizzbuzz(inputNumber));
});
});
Wednesday, June 26, 13
DEBUGGER STARTEN
$(document).ready(function () {
$('button').on('click', function () {
debugger;
var inputNumber = $('[type="number"]').val();
$('output').val(fizzbuzz(inputNumber));
});
});
Wednesday, June 26, 13
DEBUGGER STARTEN
Nachteil: Quellcode wird verändert!
Wednesday, June 26, 13
BREAKPOINTS
Wednesday, June 26, 13
BREAKPOINTS
• Haltepunkte
• Keine Änderung am Quellcode
• Können auf jede Programmzeile gesetzt werden
• Halten das Script bei Erreichen an
Wednesday, June 26, 13
BREAKPOINTS
Wednesday, June 26, 13
BREAKPOINTS
Wednesday, June 26, 13
BREAKPOINTS
Wednesday, June 26, 13
NAVIGATION
Wednesday, June 26, 13
NAVIGATION
Wednesday, June 26, 13
NAVIGATION
Wednesday, June 26, 13
NAVIGATION
Typ
Rerun
Continue
Button Shortcut Bedeutung
Shift - F8
Aktuellen Callstack nochmal
ausführen
F8
Weiterausführung zum nächsten
Breakpoint
Step into
Step over
Step out
F11 In eine Funktion hineinspringen
F10 Den Aufruf überspringen
Shift - F11
Aus der aktuellen Funktion
heraus
Wednesday, June 26, 13
SCRIPT AUSWAHL
Wednesday, June 26, 13
SCRIPTAUSWAHL
• Alle Scripts der aktuellen Seite
• Suchmöglichkeit
Wednesday, June 26, 13
SCRIPTAUSWAHL
Wednesday, June 26, 13
BEDINGTE BREAKPOINTS
Wednesday, June 26, 13
BEDINGTE BREAKPOINTS
• Häufig durchlaufene Stellen
• Fehler tritt nur bei bestimmten Bedingungen auf
Wednesday, June 26, 13
BEDINGTE BREAKPOINTS
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
• Fehler tritt auf
• Testen, ob der Fehler durch veränderte Parameter behoben
wird
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
Wednesday, June 26, 13
INHALTE MODIFIZIEREN
Wednesday, June 26, 13
BREAK ON ERROR
Wednesday, June 26, 13
BREAK ON ERROR
Wednesday, June 26, 13
BREAK ON ERROR
Wednesday, June 26, 13
STACKTRACE
Wednesday, June 26, 13
STACKTRACE
• Stack der bisher aufgerufenen Methoden
• Möglichkeit zur Navigation
Wednesday, June 26, 13
STACKTRACE
Wednesday, June 26, 13
WATCH EXPRESSIONS
Wednesday, June 26, 13
WATCH EXPRESSIONS
• Werte von Ausdrücken
• Variablen
• Objekte
• Funktionsaufrufe
• Wird kontinuierlich aktualisiert
Wednesday, June 26, 13
WATCH EXPRESSIONS
Wednesday, June 26, 13
FUNKTIONIERT DAS IMMER?
Wednesday, June 26, 13
DEBUG UMGEBUNGEN
• Callbacks testen
• zeitabhängige Funktionen
• Ajax-Calls
Breakpoints setzen, ausführen, debuggen.
Wednesday, June 26, 13
INTERVAL/TIMEOUT
• Zeit anhalten
• Breakpoint im Callback
Wednesday, June 26, 13
AJAX
• was wurde gesendet, was wurde empfangen
• Breakpoint im Callback
Wednesday, June 26, 13
Wednesday, June 26, 13
DEBUGGER
Wednesday, June 26, 13
BEISPIELCODE
var myObj = {a: 1, b: 2};
console.log(myObj);
myObj.a = 'Hello';
console.log(myObj);
for (var i = 0; i < 10; i++) {
var helper = function () {
// do something
console.log(i)
};
helper();
}
Wednesday, June 26, 13
DEBUGGER
$ node debug debugger.js
< debugger listening on port 5858
connecting... ok
break in debugger.js:1
1 var myObj = {a: 1, b: 2};
2
3 console.log(myObj);
debug>
Wednesday, June 26, 13
DEBUGGER
$ node debug debugger.js
< debugger listening on port 5858
connecting... ok
break in debugger.js:1
1 var myObj = {a: 1, b: 2};
2
3 console.log(myObj);
debug>
Wednesday, June 26, 13
DEBUGGER - STEP
Kommando Bedeutung Beschreibung
n next Fortsetzen
c cont Step over
s step Step in
o out Step out
Wednesday, June 26, 13
DEBUGGER - WATCH
• watch(expression)
• unwatch(expression)
• watchers
Wednesday, June 26, 13
DEBUGGER - WATCH
debug> watch('myObj')
debug> n
break in debugger.js:3
Watchers:
0: myObj = {"b":2,"a":1}
1 var myObj = {a: 1, b: 2};
2
3 console.log(myObj);
4
5 myObj.a = 'Hello';
debug>
Wednesday, June 26, 13
DEBUGGER - WATCH
debug> watch('myObj')
debug> n
break in debugger.js:3
Watchers:
0: myObj = {"b":2,"a":1}
1 var myObj = {a: 1, b: 2};
2
3 console.log(myObj);
4
5 myObj.a = 'Hello';
debug>
Wednesday, June 26, 13
DEBUGGER - REPL
debug> repl
Press Ctrl + C to leave debug repl
> myObj
{ b: 2, a: 1 }
> myObj.b = 14;
14
> myObj
{ b: 14, a: 1 }
debug> n
< { a: 1, b: 14 }
break in debugger.js:5
Watchers:
0: myObj = {"b":14,"a":1}
3 console.log(myObj);
4
5 myObj.a = 'Hello';
6
7 console.log(myObj);
debug>
Wednesday, June 26, 13
FRAGEN?
Wednesday, June 26, 13
KONTAKT
Sebastian Springer
sebastian.springer@mayflower.de
Mayflower GmbH
Mannhardtstr. 6
80538 München
Deutschland
@basti_springer
https://github.com/sspringer82
Wednesday, June 26, 13

More Related Content

More from Sebastian Springer

More from Sebastian Springer (20)

Schnelleinstieg in Angular
Schnelleinstieg in AngularSchnelleinstieg in Angular
Schnelleinstieg in Angular
 
Creating Enterprise Web Applications with Node.js
Creating Enterprise Web Applications with Node.jsCreating Enterprise Web Applications with Node.js
Creating Enterprise Web Applications with Node.js
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
From Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceFrom Zero to Hero – Web Performance
From Zero to Hero – Web Performance
 
Von 0 auf 100 - Performance im Web
Von 0 auf 100 - Performance im WebVon 0 auf 100 - Performance im Web
Von 0 auf 100 - Performance im Web
 
A/B Testing mit Node.js
A/B Testing mit Node.jsA/B Testing mit Node.js
A/B Testing mit Node.js
 
Angular2
Angular2Angular2
Angular2
 
Einführung in React
Einführung in ReactEinführung in React
Einführung in React
 
JavaScript Performance
JavaScript PerformanceJavaScript Performance
JavaScript Performance
 
ECMAScript 6 im Produktivbetrieb
ECMAScript 6 im ProduktivbetriebECMAScript 6 im Produktivbetrieb
ECMAScript 6 im Produktivbetrieb
 
Streams in Node.js
Streams in Node.jsStreams in Node.js
Streams in Node.js
 
JavaScript Performance
JavaScript PerformanceJavaScript Performance
JavaScript Performance
 
Große Applikationen mit AngularJS
Große Applikationen mit AngularJSGroße Applikationen mit AngularJS
Große Applikationen mit AngularJS
 
Testing tools
Testing toolsTesting tools
Testing tools
 
Node.js Security
Node.js SecurityNode.js Security
Node.js Security
 
Typescript
TypescriptTypescript
Typescript
 
Reactive Programming
Reactive ProgrammingReactive Programming
Reactive Programming
 
Best Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptBest Practices für TDD in JavaScript
Best Practices für TDD in JavaScript
 
Warum ECMAScript 6 die Welt ein Stückchen besser macht
Warum ECMAScript 6 die Welt ein Stückchen besser machtWarum ECMAScript 6 die Welt ein Stückchen besser macht
Warum ECMAScript 6 die Welt ein Stückchen besser macht
 
Lean Startup mit JavaScript
Lean Startup mit JavaScriptLean Startup mit JavaScript
Lean Startup mit JavaScript
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Debugging in JavaScript