×

javascript · level 3 · unit 7 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Professionals let tools catch mistakes before code even runs.

Real projects lean on tools. A such as ESLint reads code without running it and flags slips like == or unused variables. A such as Prettier fixes the layout automatically, so reviews can focus on ideas, not spaces.

Code you install with npm is a , listed in package.json with versions in : major.minor.patch. The range ^1.4.0 accepts any later 1.x version but never 2.0.0, because a new major number means things may break. Below is a tiny linter of your own.

const source = ["var total = 0;", "if (total == 0) { total = 1; }", "const done = true;"];
const rules = [
  { name: "no-var", broken: (line) => line.includes("var ") },
  { name: "eqeqeq", broken: (line) => line.includes(" == ") }
];
for (let i = 0; i < source.length; i++) {
  for (const rule of rules) {
    if (rule.broken(source[i])) { console.log(`line ${i + 1}: ${rule.name}`); }
  }
}
console.log("Lint finished");

Real linters understand the structure of code, not only its text, so they never mistake a string for code.