64

Improving an old JS code, replaced all 'var's with 'let's. Previous guy wrote a comment above his variables, which is now saying:
"letiabes"

Comments
  • 21
    Do not blindly "Find & Replace" in the childish way. A simple blank after "var" (Find: "var ") can do you the appropriate favour. That's just to say in this case. There're many ways to do difficult replacements. Remind that you have to be sure of what you're about to do before you actually do it.
  • 4
    @buitrung guess I'm a little less functional after being up all night. You're right tho:)
  • 4
  • 2
    @terraria99 yeah sounds fun:))
  • 8
    Also, just because var is bad practice today does not mean switching to let will work.

    Suddenly you will find that the code depends on the behavior of var and breaks with let ;)

    Personally I try to use const as much as possible now a days and only use let when there are no better option.
  • 4
    @irene Another good reason not to introduce new hard to find bugs ;)
  • 12
    Let
    Is
    Not
    A
    Replacement
    For
    Var
    Read
    The
    Fucking
    Docs
  • 1
    Please let us know how many errors you got after this :D
  • 0
    @Voxera babel will replace all let and const back to var again... 🤦‍♀️
  • 0
    "Improving old code" all the while having no idea what you're doing.
  • 2
    @ganjaman LINA RFV RTFD?
  • 0
    @electrineer umm, what's LINA and RFV?
  • 0
    @ganjaman let and const replace var though?
  • 0
    @fredisinbed

    replace = behave the same way

    No

    Replace = should not use var

    True

    Replace = replace every var with let like fucking idiot op

    Absolutely no
  • 1
    @exceptionalGuy dunno, Lina could be a name
  • 0
    @ganjaman I think most people with some knowledge of js would go for the second option. But then again, replace all can lead to fun errors x)
  • 1
    @sunfishcc sorry for the late comment, missed this response.

    Babel does this to make sure the code works on older browsers.

    But it should, and probably does, wrap every let in a function unless t already is.

    That keeps the scope of the let while using a var.

    I used hat technique when writing library code to make sure not to pollute the global namespace.

    But using functions create very strange and non intuitive code, using let and having babel transpile it means you do mot have to deal with such hard to work code.
Add Comment