Your SlideShare is downloading. ×
  • Like
JavaScript WTFs
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

JavaScript WTFs

  • 2,524 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,524
On SlideShare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
9
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Javascriptwtfs
    how I learnedtostopworrying
    andlovethebotchthatisECMAScript
  • 2. Aboutme
    Raphael Pigulla
    BörseGo AG
    Lead Developer JavaScript
    pigulla@boerse-go.de
    @muddyb0y
  • 3. WTF?
    functionfoo() {
    return
    {
    bar: true
    }
    }
    // whatis x?
    var x = bar();
  • 4. Semicolon Insertion
    functionfoo() {
    return;
    {
    bar: true;
    };
    }
    // whatis x?
    var x = bar();
  • 5. Semicolon Insertion
    { 1 2 } 3
    { 1 2 } 3;

    { 1
    ;2;} 3;
    { 1
    2 } 3

    i;
    ++
    j;

    i
    ++
    j
  • 6. WTF?
    varfoo = 42;
    function bar() {
    foo = 13;
    }
    // foois 42
    bar();
    // foois?
  • 7. WTF?
    varfoo = 42;
    function bar() {
    foo = 13;
    varfoo;
    }
    // foois 42
    bar();
    // foois?
  • 8. DeclarationHoisting
    varfoo = 42;
    function bar() {
    returnfoo;
    varfoo = 17;
    }
    // whatisthereturnvalueof bar() ?
    bar();
  • 9. FunctionScope
    var x = 42;
    functionfoo(n) {
    x = 13;
    while (--n > 0) {
    var x = 2 * n;
    }
    }
  • 10.
  • 11. String Theory
    // firstattempt
    functionisString(v) {
    returntypeof v === ´string´;
    }
    isString(new String(´foo´)); // false!
  • 12. String Theory
    // secondattempt
    functionisString(v) {
    return v instanceof String;
    }
    isString(´oh dear´); // false!
  • 13. String Theory
    // thirdattempt
    functionisString(v) {
    returntypeof v === ´string´ ||
    v instanceof String;
    }
    isString(popup.window.getSomeString());
    // mayreturnfalse
  • 14. String Theory
    // fourthattempt
    functionisString(v) {
    returnObject.prototype.toString. ⏎
    call(v) === ´[object String]´;
    }
    // untilsomejokerchanges
    // Object.prototype.toString... :-/
  • 15. // untilsomeoneoverwrites String
    // orRegExp.test-.-
    String Theory
    // fifthattempt
    functionisString(v) {
    returntypeofv ===´string´ ||
    !!v && /^function String() {/⏎
    .test(´´ + v.constructor);
    }
  • 16. WTF?
    > [] == ![]
    <Array>[] == !<Array>[]
    <Array>[] == !ToBoolean(<Array>[])
    <Array>[] == <Bool>false
    <Array>[] == ToNumber(<Bool>false)
    <Array>[] == <Number>0
    ToPrimitive(<Array>[]) == <Number>0
    <String>[].toString() ==<Number>0
    <String>´´ == <Number>0
  • 17. The Abstract EqualityComparisonAlgorithm
  • 18. What‘sthebig deal?
  • 19. Well, not foreverybody.
    for (franz=0;franz<items.length;franz++) { vare = items[franz];
    ...
  • 20.
    It turns out thatif you haveabsolutelynoideawhatyou‘redoing in thelanguage, you can still generallymakethingswork.

    Douglas Crockford
  • 21.
  • 22.
  • 23. Whydoesit matter?
    JavaScript iseverywhere
    you needfirstclass JavaScript developers
    weeding out thedudsisdifficult
    jQuery ≠ JavaScript
    jQuery
  • 24. The Checklist™
    Whatisthedifferencebetween...
    closure vs.anonymousfunction
    functionalvs. imperative languages
    prototypicalvs.class-basedinheritance
    asynchronousvs. multi-threadedcode
  • 25. Source: @markrendle on Twitter