Skip to content

globalAssignments

Reports attempting to assign to read-only global variables such as undefined, NaN, Infinity, Object, etc.

✅ This rule is included in the ts javascript presets.

Global variables like undefined, NaN, Infinity, and built-in objects like Object and Array are read-only and should not be modified. Attempting to reassign these globals can lead to confusing behavior and potential bugs in your code. In strict mode, reassigning these globals will throw a TypeError at runtime.

B0undefin5<3 sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">dB0N5<3 sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">82<42sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">dB0Infini5<3 sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">821<00sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">d53ObjecA5<3 sp ansty="le--0:#FF6A83;--1:#A248">48nu5<3;d ivclassNa="meec-li">dB0Arr5<3 sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti5<3 sp ansty="le--0:#D9F5DD;--1:#1111">11<()sp ansty="le--0:#D6DEEB;--1:#403F">53 {<};d ivclassNa="meco"><};d>AEle53couAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<25sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">B0undefin5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<+=sp ansty="le--0:#D6DEEB;--1:#403F">53 coundB0NAE<++sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">d72<--sp ansty="le--0:#82AAFF;--1:#3B61">B0Infini5<3;d ivclassNa="meco">
44AE3F53myUndef44A0<9821 spans="tyle--0:#D6DEEB;--1:#40">3c44AEco61B0notANu44A09<8242 spans="tyle--0:#D6DEEB;--1:#40">3c44AEco61B0infiniteV44A098<2100 spans="tyle--0:#D6DEEB;--1:#40">3c44AE3F53myOb44A48483c44AEco61B0myA44AE = funct11<11() spans="tyle--0:#C792EA;--1:#88">44A3< {}><;di vdivclass="Nameexpressive-">44AE3F53c44A0<9825 spans="tyle--0:#D6DEEB;--1:#40">344AE3F53undefinedV44A61B0undef33F53undefinedVa4<4AE= spans="tyle--0:#D6DEEB;--1:#40">3F53 coc44AE3F53notANu44A61B<0NaN spans="tyle--0:#D6DEEB;--1:#40">33F53notANu443c44AE3F53infiniteV44A61B0Infi36E<72-- spans="tyle--0:#D6DEEB;--1:#40">3F53infiniteVa

This rule is not configurable.

If your codebase intentionally assigns to global objects and is guaranteed to run in an environment that allows that, you might not want to enable this rule. For example, if you target a legacy runtime with legacy non-standard JavaScript semantics, modern standard practices may not apply to you.