Skip to content

constantAssignments

Reports attempting to reassign variables declared with const.

✅ This rule is included in the ts javascript presets.

The const keyword creates a read-only reference to a value, preventing reassignment. While properties of const objects and elements of const arrays can be mutated, the binding itself cannot be reassigned. Attempting to reassign a const variable results in a runtime error.

AEconsB0valAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53valuA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><2;d>AEconsB0resuAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0getVal53(<);d ivclassNa="meec-li">53resulA5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0getOtherVal53(<);d ivclassNa="meco"><);d>AEconsB0countAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53countAE<++sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><+;d>AEconst <{ sp ansty="le--0:#82AAFF;--1:#3B61">B0properAE } <= sp ansty="le--0:#D6DEEB;--1:#403F">53objec53propertA5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dnew val1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><";d>AEf53< (sp ansty="le--0:#C792EA;--1:#8844">AEconsB0itA7253 items)< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53iteA5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processIt53(item<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AE3F53v44A0<9821 spans="tyle--0:#D6DEEB;--1:#40">33F53va4<4AE= spans="tyle--0:#D6DEEB;--1:#40">30<9822 spans="tyle--0:#D6DEEB;--1:#40">3<= 2><;di vdivclass="Nameexpressive-">44AEco61B0ob44AE = { val0<9821 spans="tyle--0:#C792EA;--1:#88">4433F53ob4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72v34<4AE= spans="tyle--0:#D6DEEB;--1:#40">30<9822 spans="tyle--0:#D6DEEB;--1:#40">3<= 2><;di vdivclass="Nameexpressive-">44AEco61B0a443F<53 [ spans="tyle--0:#F78C6C;--1:#AA">0<9821 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9822 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9823 spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B030<9824 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><(4)><;di vdivclass="Nameexpressive-">44AEcons61B0prop44AE <} = spans="tyle--0:#D6DEEB;--1:#40">3F53obj3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">3F53(proper<;di vdivclass="Nameexpressive-">44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AE3F534<4AE spans="tyle--0:#7FDBCA;--1:#09">6E<72of spans="tyle--0:#D6DEEB;--1:#40">3F53 item3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53i4<4AE= spans="tyle--0:#D6DEEB;--1:#40">361B0process3F53(it3<);>

This rule is not configurable.

If your codebase relies on non-standard behavior that involves reassigning constant variables (which is highly discouraged), you might choose to disable this rule. For example, if you target a legacy runtime with non-standard JavaScript semantics, standard practices may not apply to you.