ݺߣ

ݺߣShare a Scribd company logo
1 de 27
A JOURNEY TO THEA JOURNEY TO THE
DEEPS OF INSANITYDEEPS OF INSANITY
WITH JAVASCRIPTWITH JAVASCRIPT
By Juan Ignacio Rodríguez de LeónBy Juan Ignacio Rodríguez de León
at twitterat twitter@jileon@jileon
2 de 27
DISCLAIMERDISCLAIMER
Javascript is a mix of many good ideas and a few (really)
bad ones
Spanish technical jargon for this is truño or truñaco
We are gonna have a laugh with some of the bad parts
But beware! The good parts are really good
JavaScript is like that friend of you, embarrasing, not so
clever, give you a lot of troubles, but hey! he is your friend
3 de 27
WHERE THERE IS SMOKE ...WHERE THERE IS SMOKE ...
Sombras de sospecha (Shadow of Doubt, 1998)
4 de 27
THE PARADOXTHE PARADOX
The fact is the bad parts where usually included in order
to make the language more "friendly"
A trouble-less, easygoing environment for the rookie
developer...
La cena de los idiotas (Le dîner de cons, 1998)
5 de 27
THEY WANTED TO BUILDTHEY WANTED TO BUILD
SOMETHING LIKE THISSOMETHING LIKE THIS
Blancanieves y los siete enanitos
(Snow White and the Seven Dwarfs, 1937)
6 de 27
GOT THISGOT THIS
Terminator (The Terminator, 1984)
7 de 27
THERE IS NO INTEGER TYPETHERE IS NO INTEGER TYPE
All numbers are stored as IEEE 754 floating point
What the hell were they thinking?
var a=0;
for (var i=0; i<10; i++) { a += 0.1; }
console.log(a === 10);
¿Quién engañó a Roger Rabbit?
(Who Framed Roger Rabbit, 1988)
8 de 27
¿WHAT WOULD BE THE ANSWER?¿WHAT WOULD BE THE ANSWER?
if (99999999999999999 === 100000000000000000) {
console.log(‘WTF!’);
} else {
console.log(‘Everything ok’);
}
Everything ok1.
WTF! ☑2.
Resacón en Las Vegas (The Hangover, 2009)
9 de 27
GLOBAL VARIABLES EVERYWHEREGLOBAL VARIABLES EVERYWHERE
The right way of declaring a variable is using the reserved
word var. If you forgot to use it, the compiler...
give an error, compilation stops1.
give a warning, compilation continues2.
create the variable on the appropiate scope3.
goes bananas, throws down the drain any rest of common
sense and creates a fucking global variable ☑
4.
Viaje a la perdición (Road to Perdition, 2002)
10 de 27
You make a typo, the compiler creates a
variable
THINK OF ITTHINK OF IT
fucking GLOBAL
Solo ante el peligro (High Noon, 1952)
11 de 27
FIND THE DIFFERENCEFIND THE DIFFERENCE
var f = function() {
return {
'ok': true
};
}
var f = function() {
return
{
'ok': true
};
}
El show de Truman (The Truman Show, 1998)
12 de 27
SEMICOLONSSEMICOLONS
Semicolons are “optional” in some cases
JavaScript inserts semicolons wherever he believes
appropiate
There is no warnings, there is no error. Embrace danger.
Who wants to live forever?
Just a litle question: ¿What must do a sufficiently
advanced civilization with the guy who took this desicion?
Con faldas y a lo loco (Some Like It Hot, 1959)
13 de 27
EXTERMINATE!EXTERMINATE!
Doctor Who (Doctor Who, 1963-1989, 2005~)
14 de 27
WHAT IS THE OUTPUT OF THISWHAT IS THE OUTPUT OF THIS
CODE?CODE?
function() {
var foo = 1;
var bar = 2;
alert(foo + " " + bar);
}
1 2
El Señor de los anillos: Las dos torres
(The Lord of the Rings: The Two Towers, 2002)
15 de 27
WHAT IF I CHANGE THE ORDER?WHAT IF I CHANGE THE ORDER?
function() {
var foo = 1;
alert(foo + " " + bar);
var bar = 2;
}
Raises an "Undefined variable" Exception1.
Works the same2.
Do an alert with the message “1 undefined” ☑3.
¿Victor o Victoria? (Victor Victoria, 1982)
16 de 27
HOISTINGHOISTING
The compiler does a trick named hoisting
Declarations of functions are moved to the begining of the
scope
Declarations of variables (but no the initialization) are
"hoisted" too
No error, no warning. Things are "simpler" this way
Las dos caras de la verdad (Primal Fear, 1996)
17 de 27
function() {
var foo = 1;
alert(foo + " " + bar);
var bar = 2;
}
⇩
function() {
var bar;
var foo = 1;
alert(foo + " " + bar);
bar = 2;
}
La venganza de la Pantera Rosa
(Revenge of the Pink Panther, 1978)
18 de 27
YES BITCHES!YES BITCHES!
The compiler REWRITES your source code
Escuadrón Suicida (Suicide squad, 2016)
19 de 27
What's the meaning of thisWhat's the meaning of this
In C++, Java, Python, etc. "this" (or "self", in some cases)
means the current instance of the class. In JavaScript, this is:
The global object (In a browser, windows)1.
One object calling this function as a method2.
The context passed to the function if it's called with call
or apply
3.
The recently created object, when the function is called
with new
4.
Mentiras arriesgadas (True Lies, 1994)
20 de 27
EN JAVASCRIPT, THIS IS:EN JAVASCRIPT, THIS IS:
The global object (In a browser, windows) ☑1.
One object calling this function as a method ☑2.
The context passed to the function if it's called with call
or apply ☑
3.
The recently created object, when the function is called
with new ☑
4.
Una verdad incómoda (An Inconvenient Truth, 2006)
21 de 27
ALL OF THEN!ALL OF THEN!
In other words, you have no control on the content of this. It
depends not of you, but the one who is calling your function.
Absolutly fucking reasonable
Deadpool (Deadpool, 2016)
22 de 27
SORT SORTS (SORT OF)SORT SORTS (SORT OF)
¿What is the content of var l a�er execution of this code?
var l = [1, 2, 20, 10];
l.sort();
[1, 2, 10, 20]1.
[1, 10, 2, 20] ☑2.
La lista de Schindler (Schindler's List, 1993)
23 de 27
No further questions Your honorNo further questions Your honor
Lists are ordered as if were text,Lists are ordered as if were text,
regardless of their contentregardless of their content
Agárralo como puedas (Naked Gun, 1988)
24 de 27
THAT'S ALL FOLKSTHAT'S ALL FOLKS
Just to finish, the icing on the cake:
In JavaScript you can comment lines or text blocks
The syntax used for the text blocks was borrowed from
PL/1; the /* and */ marks
Open question: Was this a good or bad option for
JavaScript?
Hint: This marks are very unlikely in PL/1
Coherence (Coherence, 2013)
25 de 27
RECOMENDATIONSRECOMENDATIONS
Use the "strict" mode
Use jslint (http://www.jslint.com/)
Learn CoffeScript (http://coffeescript.org/) or TypeScript
(http://www.typescriptlang.org/> or similar
Use frameworks and/or libraries: jQuery, Angular, Meteor,
Aurelia... there are a lot of then
Be careful out there
Star Trek: Más allá (Star Trek Beyond, 2016)
26 de 27
THANK YOU FORTHANK YOU FOR
COMINGCOMING
Questions?Questions?
27 de 27

More Related Content

Viewers also liked (7)

PDF
You Suck At PowerPoint!
Jesse Desjardins - @jessedee
PDF
Masters of ݺߣShare
Kapost
PDF
10 Ways to Win at ݺߣShare SEO & Presentation Optimization
Oneupweb
PDF
STOP! VIEW THIS! 10-Step Checklist When Uploading to ݺߣshare
Empowered Presentations
PDF
How To Get More From ݺߣShare - Super-Simple Tips For Content Marketing
Content Marketing Institute
PDF
How to Make Awesome ݺߣShares: Tips & Tricks
ݺߣShare
PDF
Getting Started With ݺߣShare
ݺߣShare
You Suck At PowerPoint!
Jesse Desjardins - @jessedee
Masters of ݺߣShare
Kapost
10 Ways to Win at ݺߣShare SEO & Presentation Optimization
Oneupweb
STOP! VIEW THIS! 10-Step Checklist When Uploading to ݺߣshare
Empowered Presentations
How To Get More From ݺߣShare - Super-Simple Tips For Content Marketing
Content Marketing Institute
How to Make Awesome ݺߣShares: Tips & Tricks
ݺߣShare
Getting Started With ݺߣShare
ݺߣShare

More from Juan Rodríguez (16)

PPTX
Estados imposibles y como evitarlos
Juan Rodríguez
PDF
Introduction to BDD (Behavior-Driven Development)
Juan Rodríguez
PDF
Vue.js: El framework javascript para muggles
Juan Rodríguez
PDF
Introducción a jupyter (antes i python notebook)
Juan Rodríguez
PDF
Presentación estetoscopio
Juan Rodríguez
PDF
Charla introducción a RaspberryPI
Juan Rodríguez
PDF
Guia (breve) de supervivencia a python 3
Juan Rodríguez
PDF
¡A todo Kanban! ~ Introducción a kanban
Juan Rodríguez
ODP
02 python Programación orientada a objetos y funcional
Juan Rodríguez
ODP
01 el lenguaje Python
Juan Rodríguez
ODP
00 introducción a Python
Juan Rodríguez
PDF
Taller de introducción al desarrollo web con Django
Juan Rodríguez
PDF
Presentación appy/pod
Juan Rodríguez
ODP
Presentacion Google Mini Adeje 16 Oct 2008
Juan Rodríguez
ODP
Algunos recursos para desarrollo Web
Juan Rodríguez
ODP
Extranet Parlamento
Juan Rodríguez
Estados imposibles y como evitarlos
Juan Rodríguez
Introduction to BDD (Behavior-Driven Development)
Juan Rodríguez
Vue.js: El framework javascript para muggles
Juan Rodríguez
Introducción a jupyter (antes i python notebook)
Juan Rodríguez
Presentación estetoscopio
Juan Rodríguez
Charla introducción a RaspberryPI
Juan Rodríguez
Guia (breve) de supervivencia a python 3
Juan Rodríguez
¡A todo Kanban! ~ Introducción a kanban
Juan Rodríguez
02 python Programación orientada a objetos y funcional
Juan Rodríguez
01 el lenguaje Python
Juan Rodríguez
00 introducción a Python
Juan Rodríguez
Taller de introducción al desarrollo web con Django
Juan Rodríguez
Presentación appy/pod
Juan Rodríguez
Presentacion Google Mini Adeje 16 Oct 2008
Juan Rodríguez
Algunos recursos para desarrollo Web
Juan Rodríguez
Extranet Parlamento
Juan Rodríguez
Ad

Recently uploaded (20)

PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
PDF
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
DOCX
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
PDF
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
PPTX
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
PDF
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
PPTX
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
DOCX
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
PDF
The Next-Gen HMIS Software AI, Blockchain & Cloud for Housing.pdf
Prudence B2B
PPTX
declaration of Variables and constants.pptx
meemee7378
PDF
Which Hiring Management Tools Offer the Best ROI?
HireME
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
PDF
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
PDF
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
The Next-Gen HMIS Software AI, Blockchain & Cloud for Housing.pdf
Prudence B2B
declaration of Variables and constants.pptx
meemee7378
Which Hiring Management Tools Offer the Best ROI?
HireME
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
Ad

Viaje al centro de la locura con Javascript

  • 2. A JOURNEY TO THEA JOURNEY TO THE DEEPS OF INSANITYDEEPS OF INSANITY WITH JAVASCRIPTWITH JAVASCRIPT By Juan Ignacio Rodríguez de LeónBy Juan Ignacio Rodríguez de León at twitterat twitter@jileon@jileon 2 de 27
  • 3. DISCLAIMERDISCLAIMER Javascript is a mix of many good ideas and a few (really) bad ones Spanish technical jargon for this is truño or truñaco We are gonna have a laugh with some of the bad parts But beware! The good parts are really good JavaScript is like that friend of you, embarrasing, not so clever, give you a lot of troubles, but hey! he is your friend 3 de 27
  • 4. WHERE THERE IS SMOKE ...WHERE THERE IS SMOKE ... Sombras de sospecha (Shadow of Doubt, 1998) 4 de 27
  • 5. THE PARADOXTHE PARADOX The fact is the bad parts where usually included in order to make the language more "friendly" A trouble-less, easygoing environment for the rookie developer... La cena de los idiotas (Le dîner de cons, 1998) 5 de 27
  • 6. THEY WANTED TO BUILDTHEY WANTED TO BUILD SOMETHING LIKE THISSOMETHING LIKE THIS Blancanieves y los siete enanitos (Snow White and the Seven Dwarfs, 1937) 6 de 27
  • 7. GOT THISGOT THIS Terminator (The Terminator, 1984) 7 de 27
  • 8. THERE IS NO INTEGER TYPETHERE IS NO INTEGER TYPE All numbers are stored as IEEE 754 floating point What the hell were they thinking? var a=0; for (var i=0; i<10; i++) { a += 0.1; } console.log(a === 10); ¿Quién engañó a Roger Rabbit? (Who Framed Roger Rabbit, 1988) 8 de 27
  • 9. ¿WHAT WOULD BE THE ANSWER?¿WHAT WOULD BE THE ANSWER? if (99999999999999999 === 100000000000000000) { console.log(‘WTF!’); } else { console.log(‘Everything ok’); } Everything ok1. WTF! ☑2. Resacón en Las Vegas (The Hangover, 2009) 9 de 27
  • 10. GLOBAL VARIABLES EVERYWHEREGLOBAL VARIABLES EVERYWHERE The right way of declaring a variable is using the reserved word var. If you forgot to use it, the compiler... give an error, compilation stops1. give a warning, compilation continues2. create the variable on the appropiate scope3. goes bananas, throws down the drain any rest of common sense and creates a fucking global variable ☑ 4. Viaje a la perdición (Road to Perdition, 2002) 10 de 27
  • 11. You make a typo, the compiler creates a variable THINK OF ITTHINK OF IT fucking GLOBAL Solo ante el peligro (High Noon, 1952) 11 de 27
  • 12. FIND THE DIFFERENCEFIND THE DIFFERENCE var f = function() { return { 'ok': true }; } var f = function() { return { 'ok': true }; } El show de Truman (The Truman Show, 1998) 12 de 27
  • 13. SEMICOLONSSEMICOLONS Semicolons are “optional” in some cases JavaScript inserts semicolons wherever he believes appropiate There is no warnings, there is no error. Embrace danger. Who wants to live forever? Just a litle question: ¿What must do a sufficiently advanced civilization with the guy who took this desicion? Con faldas y a lo loco (Some Like It Hot, 1959) 13 de 27
  • 14. EXTERMINATE!EXTERMINATE! Doctor Who (Doctor Who, 1963-1989, 2005~) 14 de 27
  • 15. WHAT IS THE OUTPUT OF THISWHAT IS THE OUTPUT OF THIS CODE?CODE? function() { var foo = 1; var bar = 2; alert(foo + " " + bar); } 1 2 El Señor de los anillos: Las dos torres (The Lord of the Rings: The Two Towers, 2002) 15 de 27
  • 16. WHAT IF I CHANGE THE ORDER?WHAT IF I CHANGE THE ORDER? function() { var foo = 1; alert(foo + " " + bar); var bar = 2; } Raises an "Undefined variable" Exception1. Works the same2. Do an alert with the message “1 undefined” ☑3. ¿Victor o Victoria? (Victor Victoria, 1982) 16 de 27
  • 17. HOISTINGHOISTING The compiler does a trick named hoisting Declarations of functions are moved to the begining of the scope Declarations of variables (but no the initialization) are "hoisted" too No error, no warning. Things are "simpler" this way Las dos caras de la verdad (Primal Fear, 1996) 17 de 27
  • 18. function() { var foo = 1; alert(foo + " " + bar); var bar = 2; } ⇩ function() { var bar; var foo = 1; alert(foo + " " + bar); bar = 2; } La venganza de la Pantera Rosa (Revenge of the Pink Panther, 1978) 18 de 27
  • 19. YES BITCHES!YES BITCHES! The compiler REWRITES your source code Escuadrón Suicida (Suicide squad, 2016) 19 de 27
  • 20. What's the meaning of thisWhat's the meaning of this In C++, Java, Python, etc. "this" (or "self", in some cases) means the current instance of the class. In JavaScript, this is: The global object (In a browser, windows)1. One object calling this function as a method2. The context passed to the function if it's called with call or apply 3. The recently created object, when the function is called with new 4. Mentiras arriesgadas (True Lies, 1994) 20 de 27
  • 21. EN JAVASCRIPT, THIS IS:EN JAVASCRIPT, THIS IS: The global object (In a browser, windows) ☑1. One object calling this function as a method ☑2. The context passed to the function if it's called with call or apply ☑ 3. The recently created object, when the function is called with new ☑ 4. Una verdad incómoda (An Inconvenient Truth, 2006) 21 de 27
  • 22. ALL OF THEN!ALL OF THEN! In other words, you have no control on the content of this. It depends not of you, but the one who is calling your function. Absolutly fucking reasonable Deadpool (Deadpool, 2016) 22 de 27
  • 23. SORT SORTS (SORT OF)SORT SORTS (SORT OF) ¿What is the content of var l a�er execution of this code? var l = [1, 2, 20, 10]; l.sort(); [1, 2, 10, 20]1. [1, 10, 2, 20] ☑2. La lista de Schindler (Schindler's List, 1993) 23 de 27
  • 24. No further questions Your honorNo further questions Your honor Lists are ordered as if were text,Lists are ordered as if were text, regardless of their contentregardless of their content Agárralo como puedas (Naked Gun, 1988) 24 de 27
  • 25. THAT'S ALL FOLKSTHAT'S ALL FOLKS Just to finish, the icing on the cake: In JavaScript you can comment lines or text blocks The syntax used for the text blocks was borrowed from PL/1; the /* and */ marks Open question: Was this a good or bad option for JavaScript? Hint: This marks are very unlikely in PL/1 Coherence (Coherence, 2013) 25 de 27
  • 26. RECOMENDATIONSRECOMENDATIONS Use the "strict" mode Use jslint (http://www.jslint.com/) Learn CoffeScript (http://coffeescript.org/) or TypeScript (http://www.typescriptlang.org/> or similar Use frameworks and/or libraries: jQuery, Angular, Meteor, Aurelia... there are a lot of then Be careful out there Star Trek: Más allá (Star Trek Beyond, 2016) 26 de 27
  • 27. THANK YOU FORTHANK YOU FOR COMINGCOMING Questions?Questions? 27 de 27