Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Squashing JavaScript Bugs

Squashing JavaScript Bugs

The web is a dirty place. Traces of stacks litter the floor; memory leaking from cracks in the ceiling. Someone lost their context in the corner. Load times are slowly crawling along the window. Join me for a live debugging session as we find and squash different kinds of browser bugs. You leave armed to stomp out your own bugs and cleanup your JavaScript app.

Github Link to GetRantr:
https://github.com/toddhgardner/getRANTR

Todd Gardner

June 15, 2017
Tweet

More Decks by Todd Gardner

Other Decks in Technology

Transcript

  1. AGENDA 1. About JavaScript 2. How to fix Bugs 3.

    Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner
  2. ''.length C: 2 1 D: <Error> A: undefined B: 1

    String.prototype.length returns the number of bytes rather than the number of characters. Unicode characters, like emoji, require two bytes.
  3. 0.1 + 0.2 C: 0.3000000000004 What will the following JavaScript

    code return? 2 D: ‘0.3’ A: 0.3 B: 0.2999999999997
  4. 2 JavaScript's floating point operations have issues with overflow rounding

    precision. 0.1 + 0.2 C: 0.3000000000004 D: ‘0.3’ A: 0.3 B: 0.2999999999997
  5. new Date(2016, 5, 31) C: 2016 May 31 What will

    the following JavaScript code return? 3 D: 2017 May 31 A: 2016 July 1 B: 2016 June 31
  6. 3 Months are zero based in Date. This specifies June

    31, which overflows to July 1. new Date(2016, 5, 31) C: 2016 May 31 D: 2017 May 31 A: 2016 July 1 B: 2016 June 31
  7. new Array(0, 1, Array(2)); C: [0, 1, [object Array]] What

    will the following JavaScript code return? 4 D: [0, 1, [undefined, undefined]] A: [0, 1, [2]] B: [0, 1, 2]
  8. 4 Instantiating an Array with multiple arguments creates an Array

    from those values. However a single argument only specifies the length. new Array(0, 1, Array(2)); C: [0, 1, [object Array]] D: [0, 1, [undefined, undefined]] A: [0, 1, [2]] B: [0, 1, 2]
  9. [10, 5, 1].sort() C: [1, 10, 5] What will the

    following JavaScript code return? 5 D: [5, 10, 1] A: [1, 5, 10] B: [10, 5, 1]
  10. 5 Array.prototype.sort's default comparator assumes String operations. All values are

    coerced and compared as Strings. [10, 5, 1].sort() C: [1, 10, 5] D: [5, 10, 1] A: [1, 5, 10] B: [10, 5, 1]
  11. Debugging is like being the detective in a crime movie

    where you're also the murderer “ Filipe Fortes
  12. Identify Isolate Resolve Prevent • Do Nothing Tests and Process

    have cost. Don’t increase them trivially.
  13. AGENDA 1. About JavaScript 2. How to fix Bugs 3.

    Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner
  14. QA Identified Bug: User cannot delete a rant from their

    timeline. Think twice, rant once. 1
  15. 2 User Identified Bug: Rant text remembered after deleted. Is

    it paranoia if “they” are actually after you?
  16. 3

  17. 3 AJAX Error POST 400 Bad Request /api/rants/ User Click

    <button type=“submit”> User Input <textarea name=“rant” id=“rant_text”> 0 characters
  18. AGENDA 1. About JavaScript 2. How to fix Bugs 3.

    Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner
  19. 1 Called with no arguments, Math.max() returns the smallest number

    in JavaScript. Math.max() C: NaN D: 10e25678 A: Infinity B: -Infinity
  20. (function foo(a, b) {}).length C: 2 What will the following

    JavaScript code return? 2 D: 21 A: undefined B: 0
  21. 2 Function.prototype.length returns the number of arguments specified in the

    function definition. (function foo(a, b) {}).length C: 2 D: 21 A: undefined B: 0
  22. 3 'The "+" operator is not preceded by a String,

    so it is considered arithmetic and attempts to coerce the following value into a Number. The gets evaluated as "0 + 42". +"42" C: “43” D: NaN A: 42 B: 43
  23. '' - '' C: <Error> What will the following JavaScript

    code return? 4 D: NaN A: '' B: ''
  24. 4 '' - '' C: <Error> D: NaN A: ''

    B: '' The "-" operator is always arithmetic, so both items are coerced into Numbers. They cannot be interpreted, and result in NaN.
  25. !!"" C: true 5 D: false A: “” B: <Error>

    JavaScript's Number type includes the concepts of positive and negative Infinity.
  26. AGENDA 1. About JavaScript 2. How to fix Bugs 3.

    Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner
  27. 6 User Identified Bug: Sometimes slow to load the page.

    Like you have something better to do?
  28. Monitoring Identified Bug: form.submit is not a function on signup

    Who would signup for this stupid service anyway? 7
  29. 7

  30. 8 Monitoring Identified Bug: “analytics is not defined” Sounds like

    a PEBKAC to me. Send them an id-10-t cable. “$ is not defined”
  31. 8

  32. AGENDA 1. About JavaScript 2. How to fix Bugs 3.

    Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner
  33. Identify Isolate Resolve Prevent The Doer- thinger The Enterprise- Ready

    Cylinder The all- powerful cloud Widgetizer Requests Generic Architecture
  34. Identify Isolate Resolve Prevent The Doer- thinger The Enterprise- Ready

    Cylinder The all- powerful cloud Widgetizer Requests Generic Architecture 51 2 7 0 Bug Count
  35. AGENDA 1. About JavaScript 2. How to fix Bugs 3.

    Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner