SlideShare a Scribd company logo
JSHint 
Learning JavaScript the Hard Way 
Adrian-Tudor Pănescu 
tudor.panescu@cynny.com
About me 
● ~5 years of Computer Science 
● Germany, Switzerland, Romania 
● NEC, CERN, Cynny Social Cloud 
● Web Applications Development 
jobs@cynny.com 2
JavaScript 
● Used first time around 2010 
● Recently moved from Python 
● Open Source: Invenio, Intro.js, silog 
jobs@cynny.com 3
First Real JavaScript Project 
● Inherited project with some (many) 
issues 
● Web Analytics/ Advertisements Web 
App 
● Shared client/ server code base 
jobs@cynny.com 4
Taming the Beast 
● First step: understand the code 
● pylint/ PEP8 → JSHint 
● Cleanup → Discovery ↔ Learning 
jobs@cynny.com 5
JSHint 
● Static code analysis 
● Highly-configurable 
● Open-source, used by: 
○ Mozilla 
○ Twitter 
○ Facebook 
○ Apache 
jobs@cynny.com 6
What would JSHint complain about? 
gcd = function(first_number, second_number) { 
var result; 
while (first_number != second_number) 
if (first_number > second_number) { 
var first_number = first_number - second_number; 
} else if (first_number <= second_number) { 
second_number -= first_number; 
} else {} 
console.log('result is:', first_number | second_number); 
}(12, 24) 
jobs@cynny.com 7
First run 
● maxerr = 50, hit that 
● Things started looking suspicious 
● Did the guys before me have any idea 
what they were doing? 
● Do I have any idea about what I am 
doing? 
jobs@cynny.com 8
eqeqeq 
● Expected '===' and instead saw '=='. 
● Anyone coming from any other 
language to JS will find this amazing 
● [ ] == 0 // true 
● [ ] === 0 // false 
jobs@cynny.com 9
eqeqeq (Cont.) 
jobs@cynny.com 10
eqeqeq (Cont.) 
jobs@cynny.com 10
eqeqeq (Cont.) 
● The Strict Equals Operator (===): shorter, 
more straight-forward algorithm 
● Better for someone accustomed to this 
behaviour 
● Inexperienced devs might miss the point of 
== and experience some sleepless nights 
jobs@cynny.com 11
foo is already defined (-W004) 
jobs@cynny.com 12
Deeper the Rabbit Hole - latedef 
jobs@cynny.com 13
Is this real life? 
● Function scope - funcscope, shadow 
● Hoisting 
● Closures 
● Missing var… but not in strict mode, 
whatever that is 
jobs@cynny.com 14
Semicolons: FUD or truth? 
jobs@cynny.com 15
Semicolons: FUD or truth? 
jobs@cynny.com 15
asi/ lastsemic (Cont.) 
● Zen of Python: “Explicit is better than 
implicit.” 
● Controversial, but smart life decision 
for (junior?) developers 
jobs@cynny.com 16
Curly 
jobs@cynny.com 17
forin 
jobs@cynny.com 18
forin (Cont.) 
● The body of a for in should be wrapped in 
an if statement to filter unwanted 
properties from the prototype. 
● So, it doesn’t work like Python…? (obv.) 
● typeof [] === ‘object’ - I am really confused 
now. 
jobs@cynny.com 19
Code quality 
● quotmark 
● immed 
● boss 
● newcap 
● expr 
● notypeof 
● freeze 
● maxlen 
● unused 
● loopfunc 
● camelcase 
● es3/ esnext 
● noempty 
● nonew 
jobs@cynny.com 20
Function over style? 
● maxparams - maybe use an args 
object? 
● maxstatements - don’t make me scroll 
● maxdepth - nests, nests everywhere 
● maxcomplexity - if for if wtf if while if 
else 
jobs@cynny.com 21
Conclusions 
● Static code analysis: controversial but will 
help novices (and not only) write 
maintainable code 
● Expose juniors to some new concepts 
○ latedef and -W004 will send you 
through a long spiritual journey 
jobs@cynny.com 22
Conclusions (Cont.) 
● Can help maintain some standards, 
especially among heterogeneous teams 
● My project had a good outcome, some 
JS learned 
● Still using JSHint 
jobs@cynny.com 23
Your questions, 
answered. 
jobs@cynny.com 24
Other tools 
● JSLint - more explanatory, explicit 
○ jslinterrors.com 
● ESLint - very configurable, check it out! 
● Google Closure Linter - strict typing 
● Flow - static type checker 
● JSure, JavaScript Lint 
jobs@cynny.com 25
How do I use it? 
● Editor plugin 
● Grunt task: grunt-contrib-jshint 
● Git hook: pre-push, merge request 
● Continuous integration step 
jobs@cynny.com 26

More Related Content

PDF
Grant Rogerson SDEC2015
PDF
"How to use TypeORM and stay alive", Andrii Andriiko
PDF
Clojure: Programming self-optimizing webapps in Lisp
PDF
iOS for Android Developers (with Swift)
PDF
Good code
PDF
Efficient JavaScript Development
PPTX
Node.js, Vagrant, Chef, and Mathoid @ Benetech
PDF
Power Leveling your TypeScript
Grant Rogerson SDEC2015
"How to use TypeORM and stay alive", Andrii Andriiko
Clojure: Programming self-optimizing webapps in Lisp
iOS for Android Developers (with Swift)
Good code
Efficient JavaScript Development
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Power Leveling your TypeScript

Similar to JSHint: Learning JavaScript the Hard Way (20)

PDF
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
PDF
Gamedev-grade debugging
PPTX
Creating a reasonable project boilerplate
PDF
Ecma6 in the wild
PDF
The Future is Here: ECMAScript 6 in the Wild
PDF
Ecma6 in the wild
PDF
Java vs. C/C++
PDF
ooc - OSDC 2010 - Amos Wenger
PPTX
High-Level Rust for Backend Programming
PDF
Universal job embedding in recommendation (public ver.)
PDF
Pentester++
PPTX
Nodejs web service for starters
ODP
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
PDF
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
PDF
Asynchronous job queues with python-rq
PDF
Unit testing legacy code
PDF
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
ODP
Cloud accounting software uk
PDF
Black Ops Testing Workshop from Agile Testing Days 2014
PPTX
.NET compiler platform codename Roslyn
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Gamedev-grade debugging
Creating a reasonable project boilerplate
Ecma6 in the wild
The Future is Here: ECMAScript 6 in the Wild
Ecma6 in the wild
Java vs. C/C++
ooc - OSDC 2010 - Amos Wenger
High-Level Rust for Backend Programming
Universal job embedding in recommendation (public ver.)
Pentester++
Nodejs web service for starters
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
Asynchronous job queues with python-rq
Unit testing legacy code
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Cloud accounting software uk
Black Ops Testing Workshop from Agile Testing Days 2014
.NET compiler platform codename Roslyn
Ad

More from Adrian-Tudor Panescu (7)

PDF
From Idead to Product in 48 Hours
PDF
TAO: Facebook's Distributed Data Store for the Social Graph
PDF
ECMAScript 2015 Tips & Traps
PDF
Parallel Prime Number Generation Using The Sieve of Eratosthenes
PDF
Companion – An intelligent agent architecture [RO]
PDF
Modelling a system using Petri Nets [RO]
PDF
Visualizing screen overlaps
From Idead to Product in 48 Hours
TAO: Facebook's Distributed Data Store for the Social Graph
ECMAScript 2015 Tips & Traps
Parallel Prime Number Generation Using The Sieve of Eratosthenes
Companion – An intelligent agent architecture [RO]
Modelling a system using Petri Nets [RO]
Visualizing screen overlaps
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
KodekX | Application Modernization Development
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Programs and apps: productivity, graphics, security and other tools
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
KodekX | Application Modernization Development
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Programs and apps: productivity, graphics, security and other tools

JSHint: Learning JavaScript the Hard Way

  • 1. JSHint Learning JavaScript the Hard Way Adrian-Tudor Pănescu tudor.panescu@cynny.com
  • 2. About me ● ~5 years of Computer Science ● Germany, Switzerland, Romania ● NEC, CERN, Cynny Social Cloud ● Web Applications Development jobs@cynny.com 2
  • 3. JavaScript ● Used first time around 2010 ● Recently moved from Python ● Open Source: Invenio, Intro.js, silog jobs@cynny.com 3
  • 4. First Real JavaScript Project ● Inherited project with some (many) issues ● Web Analytics/ Advertisements Web App ● Shared client/ server code base jobs@cynny.com 4
  • 5. Taming the Beast ● First step: understand the code ● pylint/ PEP8 → JSHint ● Cleanup → Discovery ↔ Learning jobs@cynny.com 5
  • 6. JSHint ● Static code analysis ● Highly-configurable ● Open-source, used by: ○ Mozilla ○ Twitter ○ Facebook ○ Apache jobs@cynny.com 6
  • 7. What would JSHint complain about? gcd = function(first_number, second_number) { var result; while (first_number != second_number) if (first_number > second_number) { var first_number = first_number - second_number; } else if (first_number <= second_number) { second_number -= first_number; } else {} console.log('result is:', first_number | second_number); }(12, 24) jobs@cynny.com 7
  • 8. First run ● maxerr = 50, hit that ● Things started looking suspicious ● Did the guys before me have any idea what they were doing? ● Do I have any idea about what I am doing? jobs@cynny.com 8
  • 9. eqeqeq ● Expected '===' and instead saw '=='. ● Anyone coming from any other language to JS will find this amazing ● [ ] == 0 // true ● [ ] === 0 // false jobs@cynny.com 9
  • 12. eqeqeq (Cont.) ● The Strict Equals Operator (===): shorter, more straight-forward algorithm ● Better for someone accustomed to this behaviour ● Inexperienced devs might miss the point of == and experience some sleepless nights jobs@cynny.com 11
  • 13. foo is already defined (-W004) jobs@cynny.com 12
  • 14. Deeper the Rabbit Hole - latedef jobs@cynny.com 13
  • 15. Is this real life? ● Function scope - funcscope, shadow ● Hoisting ● Closures ● Missing var… but not in strict mode, whatever that is jobs@cynny.com 14
  • 16. Semicolons: FUD or truth? jobs@cynny.com 15
  • 17. Semicolons: FUD or truth? jobs@cynny.com 15
  • 18. asi/ lastsemic (Cont.) ● Zen of Python: “Explicit is better than implicit.” ● Controversial, but smart life decision for (junior?) developers jobs@cynny.com 16
  • 21. forin (Cont.) ● The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. ● So, it doesn’t work like Python…? (obv.) ● typeof [] === ‘object’ - I am really confused now. jobs@cynny.com 19
  • 22. Code quality ● quotmark ● immed ● boss ● newcap ● expr ● notypeof ● freeze ● maxlen ● unused ● loopfunc ● camelcase ● es3/ esnext ● noempty ● nonew jobs@cynny.com 20
  • 23. Function over style? ● maxparams - maybe use an args object? ● maxstatements - don’t make me scroll ● maxdepth - nests, nests everywhere ● maxcomplexity - if for if wtf if while if else jobs@cynny.com 21
  • 24. Conclusions ● Static code analysis: controversial but will help novices (and not only) write maintainable code ● Expose juniors to some new concepts ○ latedef and -W004 will send you through a long spiritual journey jobs@cynny.com 22
  • 25. Conclusions (Cont.) ● Can help maintain some standards, especially among heterogeneous teams ● My project had a good outcome, some JS learned ● Still using JSHint jobs@cynny.com 23
  • 26. Your questions, answered. jobs@cynny.com 24
  • 27. Other tools ● JSLint - more explanatory, explicit ○ jslinterrors.com ● ESLint - very configurable, check it out! ● Google Closure Linter - strict typing ● Flow - static type checker ● JSure, JavaScript Lint jobs@cynny.com 25
  • 28. How do I use it? ● Editor plugin ● Grunt task: grunt-contrib-jshint ● Git hook: pre-push, merge request ● Continuous integration step jobs@cynny.com 26