• gens@programming.dev
    link
    fedilink
    arrow-up
    5
    ·
    6 months ago

    Lets say you use a variable named abcd in your function. And a variable named abcb in a for loop inside the same function. But because reasons you mistakenly use abcd inside that loop and modify the wrong variable, so that your code sometimes doesnt work properly.

    It’s to prevent mistakes like that.

    A similar thing is to use const when the variable is not modified.