SlideShare a Scribd company logo
1 of 33
Download to read offline
DEBUGGING JAVASCRIPT 
0 TO HEISENBERG 
Chris Morrow 
Senior UI Developer 
Video screencast: http://youtu.be/-q1z8BPFItw
WALTER WHITE
HEISENBERG
THE PLAN 
JAVASCRIPT BEST PRACTICES (throughout) 
BREAKPOINTS 
WATCHES 
USING THE CONSOLE 
CALL STACK 
CUSTOM TOOLS / UNIT TESTING
TOO MANY COOKS IN 
THE KITCHEN?
BEST PRACTICES 
AVOID GLOBAL VARIABLES 
<script> 
var now = new Date(); 
/* more code goes here */ 
function doSomething(){ 
alert('the time is ' + now); 
} 
</script> 
/* code below can overwrite "now" var */ 
<script src="js/dateLibrary.js"></script>
PROTECT YOUR VARIABLES WITH SCOPE 
<script> 
(function(){ // closure function 
var now = new Date(); 
/* more code goes here */ 
function doSomething(){ 
alert('the time is ' + now); 
} 
})(); 
</script> 
/* code below CAN'T change "now" var */
WHY DO PEOPLE HATE 
DEBUGGING JS? 
VARIABLES ARE GLOBAL IN SCOPE 
NO REQUIRED STRONG TYPING 
CROSS BROWSER COMPATIBILITY (IE!!!) 
NO CLASSES
DEBUGGING GOT YOU 
STRESSED?
BREAKPOINTS 
NAVIGATING CODE 
STANDARD 
CONDITIONAL
BREAKPOINTS 
Continue: continues code execution until we encounter 
another breakpoint 
Step Over: step through code line-by-line to get insights into 
how each line affects the variables being updated. Should 
your code call another function, the debugger won't jump into its 
code, instead stepping over so that the focus remains on the 
current function (scope). 
Step Into: like Step over, however clicking Step into at the 
function call will cause the debugger to move its execution 
to the first line in the functions definition. 
Step Out: having stepped into a function, clicking this will 
cause the remainder of the function definition to be run and 
the debugger will move its execution to the parent function
BEST PRACTICES
WATCHES
ADDING A WATCH: MULTIPLE WAYS 
k Sources: select then right-click 
k Click "+" on Watch Expressions panel 
k Right-click inside Watch Expressions panel
SCOPE VARIABLES 
k Like watches, but are only shown in scope
AND NOW A QUICK MESSAGE FROM OUR 
SPONSOR...
USING THE CONSOLE 
console.log() 
console.assert( expression, object ) 
console.table() 
Multiline Commands 
Snippets 
Live Editing
BEST PRACTICES 
DO NOT MINIFY CODE IN DEVELOPMENT
CALL STACK 
BOTTOMS UP
CRAPPY CODE
CLEAN UP YOUR CODE
DEBUGGING TOOLS 
ROLL YOUR OWN
PRE-DEBUGGING TOOLS 
JSHint / JSLint 
JsHint is more lenient than JSLint.
NOT HAPPY WITH 
JSHINT?
CUSTO MIZE I T WITH 
.jshintrc
UNIT TESTING 
QUnit: http://qunitjs.com/ 
Mocha: http://visionmedia.github.io/mocha/ 
Jasmine: http://jasmine.github.io/
REMOTE TESTING 
ADOBE EDGE INSPECT
RESOURCES / QUESTIONS? 
Chrome Dev Tools: 
https://developer.chrome.com/devtools 
Chrome Dev Tools: Tips & Tricks 
https://developer.chrome.com/devtools/docs/tips-and-tricks 
jQuery Learning Center: 
http://learn.jquery.com/javascript-101/ 
Design Patterns: 
http://addyosmani.com/resources/essentialjsdesignpatterns/book/ 
Douglas Crockford: Javascript the Good Parts 
http://javascript.crockford.com/
Debugging Javascript - 0 to Heisenberg

More Related Content

What's hot

Getting Started with Tizen TV Web Apps
Getting Started with Tizen TV Web AppsGetting Started with Tizen TV Web Apps
Getting Started with Tizen TV Web Apps
Ryo Jin
 
Site Testing with CasperJS
Site Testing with CasperJSSite Testing with CasperJS
Site Testing with CasperJS
Joseph Scott
 
Level up your front-end skills- going beyond cold fusion’s ui tags
Level up your front-end skills- going beyond cold fusion’s ui tagsLevel up your front-end skills- going beyond cold fusion’s ui tags
Level up your front-end skills- going beyond cold fusion’s ui tags
ColdFusionConference
 

What's hot (18)

Getting Started with Tizen TV Web Apps
Getting Started with Tizen TV Web AppsGetting Started with Tizen TV Web Apps
Getting Started with Tizen TV Web Apps
 
Auto Build
Auto BuildAuto Build
Auto Build
 
Using Prometheus to monitor your build pipelines
Using Prometheus to monitor your build pipelinesUsing Prometheus to monitor your build pipelines
Using Prometheus to monitor your build pipelines
 
Openstack Vagrant plugin overview
Openstack Vagrant plugin overviewOpenstack Vagrant plugin overview
Openstack Vagrant plugin overview
 
Enterprising JavaFX
Enterprising JavaFXEnterprising JavaFX
Enterprising JavaFX
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
 
Site Testing with CasperJS
Site Testing with CasperJSSite Testing with CasperJS
Site Testing with CasperJS
 
Phone gap android plugins
Phone gap android pluginsPhone gap android plugins
Phone gap android plugins
 
Level up your front-end skills- going beyond cold fusion’s ui tags
Level up your front-end skills- going beyond cold fusion’s ui tagsLevel up your front-end skills- going beyond cold fusion’s ui tags
Level up your front-end skills- going beyond cold fusion’s ui tags
 
Using Composer with WordPress
Using Composer with WordPressUsing Composer with WordPress
Using Composer with WordPress
 
IS YOUR WIDGET FAST? FIVE BEST PRACTICES TO FASTER EMBEDDABLE CONTENT
IS YOUR WIDGET FAST? FIVE BEST PRACTICES TO FASTER EMBEDDABLE CONTENTIS YOUR WIDGET FAST? FIVE BEST PRACTICES TO FASTER EMBEDDABLE CONTENT
IS YOUR WIDGET FAST? FIVE BEST PRACTICES TO FASTER EMBEDDABLE CONTENT
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS
 
End to-end testing from rookie to pro
End to-end testing  from rookie to proEnd to-end testing  from rookie to pro
End to-end testing from rookie to pro
 
Flask
FlaskFlask
Flask
 
CasperJS and PhantomJS for Automated Testing
CasperJS and PhantomJS for Automated TestingCasperJS and PhantomJS for Automated Testing
CasperJS and PhantomJS for Automated Testing
 
Vagrant and chef
Vagrant and chefVagrant and chef
Vagrant and chef
 
Introduction to phone gap
Introduction to phone gapIntroduction to phone gap
Introduction to phone gap
 
RxSwift for Beginners - how to avoid a headache of reactive programming
RxSwift for Beginners - how to avoid a headache of reactive programmingRxSwift for Beginners - how to avoid a headache of reactive programming
RxSwift for Beginners - how to avoid a headache of reactive programming
 

Viewers also liked

GeoMapFish, the Open Source WebGIS
GeoMapFish, the Open Source WebGISGeoMapFish, the Open Source WebGIS
GeoMapFish, the Open Source WebGIS
Camptocamp
 

Viewers also liked (14)

MVS: An angular MVC
MVS: An angular MVCMVS: An angular MVC
MVS: An angular MVC
 
C All 2008 7 22
C All 2008 7 22C All 2008 7 22
C All 2008 7 22
 
Csfpt ppcr mars 2017
Csfpt ppcr mars 2017Csfpt ppcr mars 2017
Csfpt ppcr mars 2017
 
You are valuable
You are valuableYou are valuable
You are valuable
 
Missing vin (1)
Missing vin (1)Missing vin (1)
Missing vin (1)
 
GeoMapFish, the Open Source WebGIS
GeoMapFish, the Open Source WebGISGeoMapFish, the Open Source WebGIS
GeoMapFish, the Open Source WebGIS
 
A Measurement Study of 4chan’s Politically Incorrect Forum and Its Effects on...
A Measurement Study of 4chan’s Politically Incorrect Forum and Its Effects on...A Measurement Study of 4chan’s Politically Incorrect Forum and Its Effects on...
A Measurement Study of 4chan’s Politically Incorrect Forum and Its Effects on...
 
Dossier Pedagogique Festival Electrochoc 12
Dossier Pedagogique Festival Electrochoc 12 Dossier Pedagogique Festival Electrochoc 12
Dossier Pedagogique Festival Electrochoc 12
 
Moving beyond Blackboard: The VLE journey at Dundee
Moving beyond Blackboard: The VLE journey at DundeeMoving beyond Blackboard: The VLE journey at Dundee
Moving beyond Blackboard: The VLE journey at Dundee
 
Maar wat is Sosiale Media?
Maar wat is Sosiale Media?Maar wat is Sosiale Media?
Maar wat is Sosiale Media?
 
announcements- Friday March 31, 2017
announcements- Friday March 31, 2017announcements- Friday March 31, 2017
announcements- Friday March 31, 2017
 
S3 a1 liberatom_leslieg
S3 a1 liberatom_lesliegS3 a1 liberatom_leslieg
S3 a1 liberatom_leslieg
 
All the basics that interior designers work on
All the basics that interior designers work onAll the basics that interior designers work on
All the basics that interior designers work on
 
LCMS-MS Method for Evaluation of PPCPs in Environmental Water
LCMS-MS Method for Evaluation of PPCPs in Environmental WaterLCMS-MS Method for Evaluation of PPCPs in Environmental Water
LCMS-MS Method for Evaluation of PPCPs in Environmental Water
 

Similar to Debugging Javascript - 0 to Heisenberg

Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...
Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...
Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...
Chartbeat
 
413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow
Andy Pemberton
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developers
Mehdi Valikhani
 
2011 py con
2011 py con2011 py con
2011 py con
Eing Ong
 

Similar to Debugging Javascript - 0 to Heisenberg (20)

Debugging Javascript
Debugging JavascriptDebugging Javascript
Debugging Javascript
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 
Cucumber meets iPhone
Cucumber meets iPhoneCucumber meets iPhone
Cucumber meets iPhone
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...
Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...
Tom Germeau: Mobile Apps: Finding the balance between performance and flexibi...
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developers
 
ID E's features
ID E's featuresID E's features
ID E's features
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in Production
 
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
 
Real world Webapp
Real world WebappReal world Webapp
Real world Webapp
 
2011 py con
2011 py con2011 py con
2011 py con
 
Debugging with VS2019
Debugging with VS2019Debugging with VS2019
Debugging with VS2019
 
20150812 4시간만에 따라해보는 windows 10 앱 개발
20150812  4시간만에 따라해보는 windows 10 앱 개발20150812  4시간만에 따라해보는 windows 10 앱 개발
20150812 4시간만에 따라해보는 windows 10 앱 개발
 
Behavioural Driven Development in Zf2
Behavioural Driven Development in Zf2Behavioural Driven Development in Zf2
Behavioural Driven Development in Zf2
 
Ultimate Productivity Tools
Ultimate Productivity ToolsUltimate Productivity Tools
Ultimate Productivity Tools
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store 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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
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
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Debugging Javascript - 0 to Heisenberg

  • 1.
  • 2. DEBUGGING JAVASCRIPT 0 TO HEISENBERG Chris Morrow Senior UI Developer Video screencast: http://youtu.be/-q1z8BPFItw
  • 5. THE PLAN JAVASCRIPT BEST PRACTICES (throughout) BREAKPOINTS WATCHES USING THE CONSOLE CALL STACK CUSTOM TOOLS / UNIT TESTING
  • 6. TOO MANY COOKS IN THE KITCHEN?
  • 7. BEST PRACTICES AVOID GLOBAL VARIABLES <script> var now = new Date(); /* more code goes here */ function doSomething(){ alert('the time is ' + now); } </script> /* code below can overwrite "now" var */ <script src="js/dateLibrary.js"></script>
  • 8. PROTECT YOUR VARIABLES WITH SCOPE <script> (function(){ // closure function var now = new Date(); /* more code goes here */ function doSomething(){ alert('the time is ' + now); } })(); </script> /* code below CAN'T change "now" var */
  • 9.
  • 10. WHY DO PEOPLE HATE DEBUGGING JS? VARIABLES ARE GLOBAL IN SCOPE NO REQUIRED STRONG TYPING CROSS BROWSER COMPATIBILITY (IE!!!) NO CLASSES
  • 11. DEBUGGING GOT YOU STRESSED?
  • 12. BREAKPOINTS NAVIGATING CODE STANDARD CONDITIONAL
  • 13. BREAKPOINTS Continue: continues code execution until we encounter another breakpoint Step Over: step through code line-by-line to get insights into how each line affects the variables being updated. Should your code call another function, the debugger won't jump into its code, instead stepping over so that the focus remains on the current function (scope). Step Into: like Step over, however clicking Step into at the function call will cause the debugger to move its execution to the first line in the functions definition. Step Out: having stepped into a function, clicking this will cause the remainder of the function definition to be run and the debugger will move its execution to the parent function
  • 16. ADDING A WATCH: MULTIPLE WAYS k Sources: select then right-click k Click "+" on Watch Expressions panel k Right-click inside Watch Expressions panel
  • 17. SCOPE VARIABLES k Like watches, but are only shown in scope
  • 18. AND NOW A QUICK MESSAGE FROM OUR SPONSOR...
  • 19.
  • 20. USING THE CONSOLE console.log() console.assert( expression, object ) console.table() Multiline Commands Snippets Live Editing
  • 21. BEST PRACTICES DO NOT MINIFY CODE IN DEVELOPMENT
  • 22.
  • 27. PRE-DEBUGGING TOOLS JSHint / JSLint JsHint is more lenient than JSLint.
  • 28. NOT HAPPY WITH JSHINT?
  • 29. CUSTO MIZE I T WITH .jshintrc
  • 30. UNIT TESTING QUnit: http://qunitjs.com/ Mocha: http://visionmedia.github.io/mocha/ Jasmine: http://jasmine.github.io/
  • 31. REMOTE TESTING ADOBE EDGE INSPECT
  • 32. RESOURCES / QUESTIONS? Chrome Dev Tools: https://developer.chrome.com/devtools Chrome Dev Tools: Tips & Tricks https://developer.chrome.com/devtools/docs/tips-and-tricks jQuery Learning Center: http://learn.jquery.com/javascript-101/ Design Patterns: http://addyosmani.com/resources/essentialjsdesignpatterns/book/ Douglas Crockford: Javascript the Good Parts http://javascript.crockford.com/