Javascriptwtfshow I learnedtostopworryingandlovethebotchthatisECMAScript
AboutmeRaphael PigullaBörseGo AGLead Developer JavaScriptpigulla@boerse-go.de@muddyb0y
WTF?functionfoo() {return	{	bar: true}}// whatis x?var x = bar();
Semicolon Insertionfunctionfoo() {return;	{	bar: true;};}// whatis x?var x = bar();
Semicolon Insertion{ 1 2 } 3{ 1 2 } 3;✖{ 1;2;} 3;{ 12 } 3✔i;++j;✔i++j
WTF?varfoo = 42;function bar() {foo = 13;}// foois 42bar();// foois?
WTF?varfoo = 42;function bar() {foo = 13;varfoo;}// foois 42bar();// foois?
DeclarationHoistingvarfoo = 42;function bar() {returnfoo;varfoo = 17;}// whatisthereturnvalueof bar() ?bar();
FunctionScopevar x = 42;functionfoo(n) {	x = 13;while (--n > 0) {var x = 2 * n;}}
String Theory// firstattemptfunctionisString(v) {returntypeof v === ´string´;}isString(new String(´foo´)); // false!
String Theory// secondattemptfunctionisString(v) {return v instanceof String;}isString(´oh dear´); // false!
String Theory// thirdattemptfunctionisString(v) {returntypeof v === ´string´ ||	v instanceof String;}isString(popup.window.getSomeString());// mayreturnfalse
String Theory// fourthattemptfunctionisString(v) {returnObject.prototype.toString. ⏎call(v) === ´[object String]´;}// untilsomejokerchanges// Object.prototype.toString... :-/
// untilsomeoneoverwrites String// orRegExp.test-.-String Theory// fifthattemptfunctionisString(v) {returntypeofv ===´string´ ||!!v && /^function String\(\) {/⏎		.test(´´ + v.constructor);}
WTF?> [] == ![] <Array>[] == !<Array>[]<Array>[] == !ToBoolean(<Array>[]) <Array>[] == <Bool>false <Array>[] == ToNumber(<Bool>false) <Array>[] == <Number>0ToPrimitive(<Array>[]) == <Number>0<String>[].toString() ==<Number>0 <String>´´ == <Number>0
The Abstract EqualityComparisonAlgorithm
What‘sthebig deal?
Well, not foreverybody.for (franz=0;franz<items.length;franz++) {	vare = items[franz];...
“It turns out thatif you haveabsolutelynoideawhatyou‘redoing in thelanguage, you can still generallymakethingswork.„Douglas Crockford
Whydoesit matter?JavaScript iseverywhereyou needfirstclass JavaScript developersweeding out thedudsisdifficultjQuery ≠ JavaScriptjQuery
The Checklist™Whatisthedifferencebetween...closure vs.anonymousfunctionfunctionalvs. imperative languagesprototypicalvs.class-basedinheritanceasynchronousvs. multi-threadedcode
Source: @markrendle on Twitter

JavaScript WTFs