Skip to content

implicitGlobals

Prevents implicit global variable declarations in browser scripts.

✅ This rule is included in the browser logical presets.

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.

AEva53globalCountAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">dAEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0incrementCount11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">53< sp ansty="le--0:#D7DBE0;--1:#403F">53globalCountAE<++sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
6376// Use let or const - they don't create window proper44AE3F53globalCou44A0<9820 spans="tyle--0:#D6DEEB;--1:#40">3c44AEfunc361B0incrementCou11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">3F<53 spans="tyle--0:#D7DBE0;--1:#40">3F53globalCou4433<+;><}di vdivclass="Nameexpressive-">6376// Or use a module with ex44AEexport co61B0globalCou44A0<9820 spans="tyle--0:#D6DEEB;--1:#40">3c44AEex344AEfunc361B0incrementCou11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de6376//< .. .divclass="Nameec-">3<..><}di vdivclass="Nameexpressive-">6376// Or explicitly assign to window if truly ne6E72wi4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72globalCou34<4AE= spans="tyle--0:#D6DEEB;--1:#40">30<9820 spans="tyle--0:#D6DEEB;--1:#40">3c6E72wi4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0incrementCou34<4AE= spans="tyle--0:#D6DEEB;--1:#40">344AEfunc311<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de6E72wi4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72globalCou4433F<53} ;divclass="Name"><;}>

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.