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

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
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
 

Recently uploaded (20)

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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Debugging in JavaScript