Skip to content

implicitGlobals

Prevents implicit global variable declarations in browser scripts.

✅ This rule is included in the browser logical preset.

In browser scripts (non-module code), top-level var declarations and function declarations create properties on the global window object. This can lead to unexpected behavior and naming conflicts with other scripts loaded in the same page.

This rule flags top-level var declarations and function declarations in non-module scripts. It encourages developers to either use modules (with import/export), use let or const declarations (which don’t create globals), or explicitly assign to window if global access is truly needed.

var globalCounter = 0;
function incrementCounter() {
globalCounter++;
}

This rule is not configurable.

If you’re working with legacy non-module browser code where globals are intentional and there’s no risk of naming conflicts, you might disable this rule. For modern applications, prefer using modules and avoiding implicit globals.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.