The top 5 JavaScript
issues in all our codebases

Phil Nash

Phil Nash
Developer Advocate for Sonar

Sonar
Logos

Phil Nash

twitter.com/philnash

@philnash@mastodon.social

linkedin.com/in/philnash

https://philna.sh

Phil Nash

The data

JavaScript Issues

Clean Code

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Code for readability.

John F. Woods - 1991 on comp.lang.c++

The comma operator

if (condition)
  avar = value, anothervar = anothervalue;

The comma operator

if (condition)
  avar = value; anothervar = anothervalue;

Design for readability. Even if you don't intend anybody else to read your code, there's still a very good chance that somebody will have to stare at your code and figure out what it does: That person is probably going to be you, twelve months from now.

Raymond Chen - The Old New Thing Microsoft Blog

Clean Code

It runs better in production and
it is better to work with in development

So what are the top 5 issues?

So what are the top 5 issues?

A list of top issues for JavaScript
JavaScript
1.
2.
3.
4.
5.

So what are the top 5 issues?

A list of top issues for JavaScript
JavaScript
1.
2.
3.
4.
5. Unused assignments should be removed

Unused assignments
should be removed

            foo = bar + baz;
foo = otherFunction();

Unused assignments
should be removed

function add(a, b) {
  return result = a + b;
}

So what are the top 5 issues?

A list of top issues for JavaScript
JavaScript
1.
2.
3.
4.
5. Unused assignments should be removed

So what are the top 5 issues?

A list of top issues for JavaScript
JavaScript
1.
2.
3.
4. "===" and "!==" instead of "==" and "!="
5. Unused assignments should be removed

==

Double equals is a bad idea https://dorey.github.io/JavaScript-Equality-Table/

===