← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Implicit Globals & strict mode

javascript ES5 Intermediate
debt(d3/e3/b5/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). The term's detection_hints lists ESLint and TypeScript as tools, and automated detection is marked yes. ESLint's no-undef rule is a standard/default-adjacent rule that catches accidental globals and missing declarations, placing this firmly at the linter-catches level rather than needing a specialist tool.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix says: add 'use strict' to all non-module scripts, enable ESLint no-undef, use TypeScript, or switch to ES modules. This is a small but non-trivial fix — it may touch multiple script files but follows a clear pattern (add directive, fix declarations) without requiring deep architectural change.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). Implicit globals apply to web and CLI contexts broadly. In long-running apps and test suites, state leakage and test interference are ongoing costs that slow multiple work streams (debugging mysterious state, flaky tests, memory leaks). The burden is not purely localised but not quite architectural in weight.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field states that developers assume 'use strict' is optional because ES modules are strict by default — but classic scripts still need it explicitly. This is a well-documented gotcha that many developers learn the hard way, especially when mixing module and classic script loading contexts. It contradicts a reasonable inference from modern JS defaults.

About DEBT scoring →

TL;DR

Assigning to an undeclared variable in non-strict mode silently creates a global — use 'use strict' or ES modules to prevent accidental global pollution.

Explanation

In non-strict mode, assignment to an undeclared variable creates a global: function foo() { x = 5; } sets window.x (browser) or global.x (Node). This is a silent bug that pollutes the global scope. 'use strict' throws ReferenceError instead. ES modules ('type': 'module') are automatically strict. Implicit globals are a source of cross-frame pollution in browsers, race conditions in async code, and test pollution. They're also a memory leak source — globals are never GC'd. TypeScript catches all implicit globals at compile time.

Common Misconception

'use strict' is optional in modern JS — ES modules are strict by default, but classic scripts are not. 'use strict' is still needed for classic script tags.

Why It Matters

Implicit globals in long-running apps or test suites cause test interference, state leakage, and memory leaks that are extremely hard to debug.

Common Mistakes

  • Forgetting var/let/const in a loop: for (i = 0; ...) creates global i.
  • Module code that assumes strict mode but is loaded as a classic script.
  • Not checking for accidental globals in test setup/teardown.

Code Examples

✗ Vulnerable
function processUser(name) {
    userName = name; // Creates global 'userName' silently!
}
processUser('Paul');
console.log(window.userName); // 'Paul' — global pollution
✓ Fixed
'use strict';

function processUser(name) {
    let userName = name; // Local — no global pollution
    // Or: 'use strict' would throw ReferenceError without declaration
}

// ES modules are strict by default:
// <script type="module">

Added 22 Mar 2026
Edited 5 Apr 2026
Views 21
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S
No pings yet today
Amazonbot 9 Unknown AI 4 Google 2 Perplexity 2 ChatGPT 1 Majestic 1 Ahrefs 1
crawler 16 crawler_json 1 pre-tracking 3
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Add 'use strict' to all non-module scripts. Enable ESLint no-undef rule. Use TypeScript. Prefer ES modules (type=module) which are strict by default.
📦 Applies To
javascript ES5 web cli
🔗 Prerequisites
🔍 Detection Hints
'use strict'
Auto-detectable: ✓ Yes eslint typescript
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Medium ✓ Auto-fixable Fix: Low Context: File

✓ schema.org compliant