Things get crazy pretty quickly when it comes to scope and context, which is why most libraries / eslint rules enforce const usage and discourage mutating.
functioncreateCounter(){letval=0;// stateful value that lives in createCounter contextfunctionrunCounter(){val++;// mutatereturnval;}returnrunCounter;}constcount=createCounter();// count is a function that runs counterconstval1=count();// val1 == 1constval2=count();// val2 == 2constval3=count();// val3 == 3constdifferentCount=createCounter();// establish separate counter with separate stateconstval4=differentCount();// val4 == 1constval5=differentCount();// val5 == 2
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Things get crazy pretty quickly when it comes to scope and context, which is why most libraries / eslint rules enforce
const
usage and discourage mutating.