SlideShare a Scribd company logo
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;}}
JavaScript WTFs
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
JavaScript WTFs
JavaScript WTFs
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
Ad

Recommended

PPTX
C Best and Worst Practices in Embedded
GlobalLogic Ukraine
ย 
PDF
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
Chris Ohk
ย 
PDF
Introduction to Compiler Development
Logan Chien
ย 
PDF
C++ Programming - 11th Study
Chris Ohk
ย 
PDF
01 Jo P Jan 07
Ganesh Samarthyam
ย 
PPTX
Function therory
Tuomas Hietanen
ย 
PPT
Intro to c programming
Prabhu Govind
ย 
PPTX
Javascript: Conceptos bรกsicos
Belatrix Software
ย 
PPTX
Virtual machines - how they work
Bartosz Sypytkowski
ย 
PDF
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Bartlomiej Filipek
ย 
PDF
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
Joel Porquet
ย 
PDF
9. pointer, pointer & function
์›…์‹ ์ „
ย 
PDF
2 data and c
MomenMostafa
ย 
DOC
1
guestc66a38
ย 
PPTX
CHAPTER 4
mohd_mizan
ย 
PDF
runtimestack
Teddy Hsiung
ย 
PDF
C++ Programming - 1st Study
Chris Ohk
ย 
PDF
C
arunsahoo90
ย 
DOCX
Arduino light tracking code with 4 stepper motors
Jeff Apol
ย 
PPT
Cbasic
rohitladdu
ย 
PPSX
Programming in C [Module One]
Abhishek Sinha
ย 
PDF
C programming day#1
Mohamed Fawzy
ย 
PDF
[C++ korea] effective modern c++ study item 3 understand decltype +์ด๋™์šฐ
Seok-joon Yun
ย 
DOCX
A JavaScript Master Class - From the Wows to the WTFs
Shahriar Hyder
ย 
PDF
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
ย 
PPT
JavaScript Data Types
Charles Russell
ย 
PPTX
Dan Shappir "JavaScript Riddles For Fun And Profit"
Fwdays
ย 
PPTX
Introduction to JavaScript - Web Programming
tyfeng7
ย 
PPTX
Weird Javascript Weekends first session presentaion
SrishtyMangutte
ย 
PPTX
Chapter 1 .pptx
MohamedAbdullahiYusu
ย 

More Related Content

What's hot (15)

PPTX
Virtual machines - how they work
Bartosz Sypytkowski
ย 
PDF
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Bartlomiej Filipek
ย 
PDF
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
Joel Porquet
ย 
PDF
9. pointer, pointer & function
์›…์‹ ์ „
ย 
PDF
2 data and c
MomenMostafa
ย 
DOC
1
guestc66a38
ย 
PPTX
CHAPTER 4
mohd_mizan
ย 
PDF
runtimestack
Teddy Hsiung
ย 
PDF
C++ Programming - 1st Study
Chris Ohk
ย 
PDF
C
arunsahoo90
ย 
DOCX
Arduino light tracking code with 4 stepper motors
Jeff Apol
ย 
PPT
Cbasic
rohitladdu
ย 
PPSX
Programming in C [Module One]
Abhishek Sinha
ย 
PDF
C programming day#1
Mohamed Fawzy
ย 
PDF
[C++ korea] effective modern c++ study item 3 understand decltype +์ด๋™์šฐ
Seok-joon Yun
ย 
Virtual machines - how they work
Bartosz Sypytkowski
ย 
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Bartlomiej Filipek
ย 
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
Joel Porquet
ย 
9. pointer, pointer & function
์›…์‹ ์ „
ย 
2 data and c
MomenMostafa
ย 
CHAPTER 4
mohd_mizan
ย 
runtimestack
Teddy Hsiung
ย 
C++ Programming - 1st Study
Chris Ohk
ย 
Arduino light tracking code with 4 stepper motors
Jeff Apol
ย 
Cbasic
rohitladdu
ย 
Programming in C [Module One]
Abhishek Sinha
ย 
C programming day#1
Mohamed Fawzy
ย 
[C++ korea] effective modern c++ study item 3 understand decltype +์ด๋™์šฐ
Seok-joon Yun
ย 

Similar to JavaScript WTFs (20)

DOCX
A JavaScript Master Class - From the Wows to the WTFs
Shahriar Hyder
ย 
PDF
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
ย 
PPT
JavaScript Data Types
Charles Russell
ย 
PPTX
Dan Shappir "JavaScript Riddles For Fun And Profit"
Fwdays
ย 
PPTX
Introduction to JavaScript - Web Programming
tyfeng7
ย 
PPTX
Weird Javascript Weekends first session presentaion
SrishtyMangutte
ย 
PPTX
Chapter 1 .pptx
MohamedAbdullahiYusu
ย 
PPT
An introduction to javascript
MD Sayem Ahmed
ย 
PDF
Java script summary
maamir farooq
ย 
PPTX
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
.NET Conf UY
ย 
PDF
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
Codemotion
ย 
PPTX
Javascript
Prashant Kumar
ย 
PDF
Js in-ten-minutes
Phong Vรขn
ย 
PDF
javascript objects
Vijay Kalyan
ย 
PPT
fundamentals of JavaScript for students.ppt
dejen6
ย 
PPT
Basics of Javascript
Universe41
ย 
PPTX
All of javascript
Togakangaroo
ย 
PPT
Les origines de Javascript
Bernard Loire
ย 
PPT
The JavaScript Programming Language
Raghavan Mohan
ย 
PPT
The Java Script Programming Language
zone
ย 
A JavaScript Master Class - From the Wows to the WTFs
Shahriar Hyder
ย 
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
ย 
JavaScript Data Types
Charles Russell
ย 
Dan Shappir "JavaScript Riddles For Fun And Profit"
Fwdays
ย 
Introduction to JavaScript - Web Programming
tyfeng7
ย 
Weird Javascript Weekends first session presentaion
SrishtyMangutte
ย 
Chapter 1 .pptx
MohamedAbdullahiYusu
ย 
An introduction to javascript
MD Sayem Ahmed
ย 
Java script summary
maamir farooq
ย 
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
.NET Conf UY
ย 
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
Codemotion
ย 
Javascript
Prashant Kumar
ย 
Js in-ten-minutes
Phong Vรขn
ย 
javascript objects
Vijay Kalyan
ย 
fundamentals of JavaScript for students.ppt
dejen6
ย 
Basics of Javascript
Universe41
ย 
All of javascript
Togakangaroo
ย 
Les origines de Javascript
Bernard Loire
ย 
The JavaScript Programming Language
Raghavan Mohan
ย 
The Java Script Programming Language
zone
ย 
Ad

Recently uploaded (20)

PDF
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
ย 
PPTX
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
ย 
PDF
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
ย 
PDF
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
ย 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
ย 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
ย 
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
ย 
PDF
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
ย 
PDF
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
ย 
PDF
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
ย 
PPTX
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
ย 
PDF
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
ย 
PDF
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
ย 
PDF
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
ย 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
ย 
PDF
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
ย 
PDF
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
ย 
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
ย 
PPTX
Wenn alles versagt - IBM Tape schรผtzt, was zรคhlt! Und besonders mit dem neust...
Josef Weingand
ย 
PDF
โ€œMPU+: A Transformative Solution for Next-Gen AI at the Edge,โ€ a Presentation...
Edge AI and Vision Alliance
ย 
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
ย 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
ย 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
ย 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
ย 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
ย 
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
ย 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
ย 
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
ย 
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
ย 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
ย 
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
ย 
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
ย 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
ย 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
ย 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
ย 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
ย 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
ย 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
ย 
Wenn alles versagt - IBM Tape schรผtzt, was zรคhlt! Und besonders mit dem neust...
Josef Weingand
ย 
โ€œMPU+: A Transformative Solution for Next-Gen AI at the Edge,โ€ a Presentation...
Edge AI and Vision Alliance
ย 
Ad

JavaScript WTFs