05

Global Data


Symptom

Module-level variables, singletons, or shared mutable state that any code can read or mutate from anywhere.

Goal

Access goes through a small named function that owns the read/write contract — and ideally narrows it (read-only, validated).

Smellier version
let currentUser = null;
// ...some files later...
currentUser = newUser;
Fresher version
function setCurrentUser(user) {
  currentUser = validate(user);
}
function getCurrentUser() {
  return currentUser;
}
Savings

All access sites become trivially findable; you can add logging, validation, or a cache without touching consumers.

Note

The blast radius of any change is the whole codebase; behavior depends on hidden write order between unrelated callers.