Conffab by Web Directions
  • Speakers
  • Presentations
  • Conferences
  • Live streams
  • Topics
  • Pricing & Plans
  • Browse
  • Signup
  • Sign In
  • Speakers
  • Presentations
  • Conferences
  • Live streams
  • Topics
  • Pricing & Plans
  • Browse
  • Signup
  • Sign In

Search Conffab

Search presentations, speakers, transcripts, slides and topics.

Searching Conffab

Eliminate JavaScript Code Smells

Elijah Manor at Code 2015
  • JavaScript
Sign up for Conffab Free to watch this and hundreds of other videos for free
  • Details
  • References
  • Keypoints

Have you ever written JavaScript that reeked, but you couldn’t quite figure out why? Or have you written code and immediately knew that it wasn’t good, but didn’t know a better way?

Your JavaScript may pass stardard JSHint rules, but that doesn’t mean it’s legit.

“A code smell is a surface indication that usually corresponds to a deeper problem in the system” –Martin Fowler

Most developers can smell brittle and fragile code a mile away, but it takes time and training to combat against these smells. Code smells scream to be refactored.

In this session we will discuss various common smelly code snippets and discuss techniques on how we can eliminate and protect against their pungent odors creeping into your codebase.

View the slides from Elijah’s presentation.

Convoluted Code Smell – too many statements, too much depth, too complex. But what does “complex” mean? JSHint can tune for these factors and give a complexity score. It can throw errors when there are too many arguments or callbacks, etc… Then when you write tests and refactor, you can put numbers on the reduction in complexity.

Copy Paste Code Smell – duplication in code. There are tools like Jsinspect, JSCPD, CodePen which can detect copy+paste code. You can adjust how exactly it needs to match.

Switch Statement Smell – when code violates the Open/Closed Principle (OCP), one of Uncle Bob’s SOLID Principles. Instead you can use the Strategy Design Pattern to add new code without touching existing code. Sadly… no tooling for this.

Edge cases? ESLint and JSHint can be disabled for a few lines if you need to.

The This Abyss – this=that, etc. Alternatives… bind, second param on forEach, ES6 fat arrow =>…

Long string concatenation smell – ugly string concatenation with lots of quoting. Alternatives? Tomas Fuchs tweet sized js templating engine. ES6 template strings, including multiline! Or use a full templating or mvc option.

Jquery Inquiry – excessive use of fluent code, where everything is chained. Problem is silent error handling vs long chains of code. Instead refactor out to use delegated events. Put less in document ready.

Temperamental Timer Smell – use of setInterval; which then gets out of sync. Use settimeout with a callback instead, so you can’t get out of sync.

Repeat Reassign Smell – repetition. Lots of options, although many feel just as repetitive… Using reduce works… but ended up using lodash flow.

Incessant Interaction Smell – code that needs to be debounced (autocompletes, listening to scroll events, etc). This is better than throttling as it waits for a pause from the user before making calls.

Anonymous Algorithm Smell – when there are anonymous functions used in ways that mess up stack traces, code reuse, etc. Wherever you currently use an anon function, you can name it.

Last thoughts… Eslint is pluggable, so if you want to test something in particular you can write your own (or just as likely someone else has already done that). There are plugins for angular, react, backbone… npm search for eslint plugins!

(lots of code in this one, if you are interested look up the slides)

elijahmanor.com/talks/js-smells

 

You may also be interested in

Thumbnail for Fine-grained everything

Fine-grained everything

Rich Harris

performance.now() 2025

Thumbnail for Cranking View Transitions up to 11

Cranking View Transitions up to 11

Bramus Van Damme

CSS Day 2026

Thumbnail for LoAF

LoAF

Andy Davies

performance.now() 2025

Thumbnail for CSS Doom Lasers

CSS Doom Lasers

Niels Leenheer

CSS Day 2026

Thumbnail for A Love Letter to CSS Variables

A Love Letter to CSS Variables

Danny Banks

Clarity ’23

Thumbnail for Understanding Recursion for Elegant Solutions

Understanding Recursion for Elegant Solutions

Ryan Yu

Web Directions Developer Summit 2025

Thumbnail for The behaviour of browsers and their loading of resources

The behaviour of browsers and their loading of resources

David Johnston

Web Directions Code 2025

Thumbnail for How to work with generative AI in JavaScript

How to work with generative AI in JavaScript

Phil Nash

Dev Summit ’24

More presentations from Code 2015

Thumbnail for The State of the Animation

The State of the Animation

Rachel Nabors

Code 2015

Thumbnail for What Comes Next for the Web Platform?

What Comes Next for the Web Platform?

Alex Russell

Code 2015

Thumbnail for Async and Await

Async and Await

James Hunter

Code 2015

Thumbnail for Async Frontiers in JavaScript

Async Frontiers in JavaScript

Domenic Denicola

Code 2015

Thumbnail for Classing up ES6

Classing up ES6

Andy Sharman

Code 2015

Thumbnail for Canvas Cold War

Canvas Cold War

Simon Swain

Code 2015

Thumbnail for Current Best Practice in Front End Ops

Current Best Practice in Front End Ops

Alex Sexton

Code 2015

Thumbnail for Stop the Fanaticism – Using the Right Tools for the Job

Stop the Fanaticism – Using the Right Tools for the Job

Kassandra Perch

Code 2015

© 2026

  • About
  • Speakers
  • Presentations
  • Conferences
  • Contact
  • Sign in
Sign Up