If you’ve answered yes to any of these questions, then this blog is for you.
In this blog I will teach you what JSLint is, the basics of how it works and why it’s important. We will also learn how to pass your code through JSLint and use its warnings as a way to find bugs and avoid common mistakes.
JSLint is a tool written by Douglas Crockford which attempts to address this problem by analyzing your code and pointing out potential problem areas.
Think of JSLint as an automated version of yourself (only much more pedantic). It will be able to discover syntax errors that you would normally miss during initial testing, thus saving you time from having to track them down later when they become actual bugs.
JSLint is a very strict linting tool that enforces a set of coding guidelines to help you write better code. It will only allow you to do things in your code that are “safe” and “efficient.”
Errors in your if and for statements
Too many parameters for functions
If you are anything like me, you’ve probably downloaded a bunch of jQuery plugins and scripts that you were going to use in your next project. However, before you get started, the first thing you should do is run those files through JSLint.
Why should I use it?
I use JSLint because it helps me catch bugs before they make their way into production code. It can catch a wide variety of common mistakes such as implicit type coercion, missing semicolons, and even poorly written regular expressions. As an added bonus, you can also configure JSLint with your own custom options too!
How do I use it?
There are two ways
The messages that JSLint produces are intended to be self-explanatory and are listed in alphabetical order so that they can be used as a checklist for your code reviews. For example:
‘===’ should be ‘==’.
‘x’ was used before it was defined.
Comma warnings can be turned off with ‘lax comma’.
Missing ‘use strict’ statement.