Coding Standards

JavaScript Coding Standards

Foundational

The full reference for modern, safe JavaScript: variables, equality, functions and this, modules, immutability, objects and arrays, async, iteration, and security. JavaScript has well-known traps (coercion, hoisting, mutation, this, floating promises). These standards keep you in the safe modern subset. We write TypeScript by default (see TypeScript Coding Standards), and all of this applies underneath it.

Modern JavaScript (ES2015 and later) fixed most of the language's old hazards, as long as you use it and avoid the legacy behaviours. This page guides you to that safe subset, whether you are in a plain .js file (build scripts, config) or writing the JavaScript that sits under TypeScript and React.

ESLint and Prettier enforce most of this automatically. The rules here are the reasoning and the things tools cannot catch. Fix lint warnings rather than disabling rules.

Variables & scope

Equality & coercion

Functions & this

Objects, arrays & immutability

Modules & structure

Async & errors

Iteration & language use

Safety & security

Safe modern JavaScript, end to end

Coercion, mutation, floating promise var items = getItems();
if (items.count == '0') return; // var plus loose equality
items.list.push(newItem); // mutating shared state
save(items); // promise ignored (floating)

var and == invite coercion bugs, the push mutates shared state (which breaks change detection in React), and the unawaited save can fail silently. All avoidable mistakes.

const, strict, immutable, awaited const items = getItems();
if (items.count === 0) return;
const updated = { ...items, list: [...items.list, newItem] }; // new value
await save(updated); // handled

Block-scoped consts, strict equality, an immutable update, and an awaited async call. Predictable and safe.

Self-review checklist

Why it matters: JavaScript will happily run code that is subtly broken: coercion surprises, mutation bugs, ignored async failures, injection holes. Sticking to the modern safe subset and letting linters enforce it removes those traps and gives a consistent, trustworthy base under our TypeScript and React.