Loading JavaScript Linter...
Please wait a moment

How to Lint JavaScript - Step by Step Guide

Step 1

Add your JavaScript

Any plain JavaScript works, from a three-line snippet to a whole file:

•
Paste it: drop the code into the editor on the left. On a phone, the Paste button reads your clipboard.
•
Upload a file: pick a .js, .mjs, .cjs or .jsx file. An empty file is ignored and your current code stays put.
•
Try the sample: Sample loads a short snippet with a var, a loose comparison, dead code, a repeated key and an empty catch block.

Example: JavaScript Code to Lint

This function runs, but it has a few problems a reviewer would point out:

function calculateSum(a, b) {
  var result = a + b;
  if (result == 0) {}
  return result;
  console.log(result);
}
Step 2

Read the results

About half a second after you stop typing, the code is parsed. If it doesn't parse, you see the first syntax error with a pointer to it and nothing else. If it does, these eight ESLint rules run on the syntax tree, so text inside strings, comments and regular expressions is never mistaken for code:

•
eqeqeq: flags == and != (loose comparison converts types first; use === and !==)
•
no-var: flags var declarations (let and const keep a variable inside its block)
•
no-debugger: flags debugger statements left in the code
•
no-console: notes console.log and other console calls, unless you declared your own console
•
no-unreachable: flags code after return, throw, break, continue, or a loop that never ends
•
no-cond-assign: flags = used as an if, while or ternary condition, unless wrapped in an extra pair of brackets
•
no-empty: flags empty blocks and switch statements (empty functions and blocks with a comment are fine)
•
no-dupe-keys: flags an object literal that repeats a key, so one value silently overwrites the other

That's the whole list. It is not a full ESLint run: there's no config, no plugins, and no unused-variable or style checks.

Example: Linting Results

For the function above, the page reports:

  • Line 2, column 3 · Warning no-var
  • Line 3, column 14 · Warning eqeqeq
  • Line 3, column 20 · Warning no-empty
  • Line 5, column 3 · Note no-console
  • Line 5, column 3 · Warning no-unreachable
Step 3

Fix and check again

Change the code right in the editor; while it is being re-checked the results panel says Checking…, so you never read a result for older text. Findings come in three kinds:

•
Errors: the code doesn't parse, or it is TypeScript or JSON rather than JavaScript
•
Warnings: code that runs but is likely a mistake
•
Notes: console calls, fine while debugging

Want the code itself tidied up? The JavaScript Formatter handles layout, and the JavaScript Validator is there when all you need is a yes or no on the syntax.

Frequently Asked Questions

Which rules does this linter check?

First it parses your code; a syntax error is reported on its own with the line, column and a pointer to the spot. If the code parses, it runs eight rules that ESLint also has, with their default settings: eqeqeq, no-var, no-debugger, no-console, no-unreachable, no-cond-assign, no-empty and no-dupe-keys. Every finding shows the rule name, so you can look it up in the ESLint docs.

Is this the same as running ESLint?

No. It covers only those eight rules, and for them it reports the same lines and columns ESLint does. There is no config file, no plugins, no autofix, and no checks for unused or undefined variables, React hooks or code style. For a real project, run ESLint itself; this page is for a quick look at a snippet or a single file.

Why don't I get warnings about semicolons, spacing or indentation?

Those are style questions that teams settle differently, and a formatter handles them better than warnings do. This page sticks to things that are usually real mistakes. If you want the layout tidied, run the code through a JavaScript formatter instead.

What happens with JSX, TypeScript or JSON?

JSX is accepted, so React components in .js or .jsx files are checked like any other code. TypeScript is recognised and named, but not linted: type annotations and interfaces make a .js file fail, so you get that message instead of rule warnings. JSON pasted by mistake is named as JSON.

Can it fix the problems for me?

No, it only reports them. Your code in the editor is never changed. Copy and Download give you the report as plain text, with each finding on its own line, which is handy for a code review or a ticket.

Is my code uploaded anywhere?

No. The parsing and the checks run in your browser, and the code is not sent to our server or kept anywhere. Reload the page and the editor starts empty.