How to choose between let and const in JavaScript (just use let!)

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 4

  • @RyanThickett
    @RyanThickett Год назад +2

    This is bad advice, use const everywhere until your editor complains because you're trying to reassign something, at the point you need to use let. It's more efficient to use const for your programs and can be a great habit for transitioning to stacks with React/Angular etc...

    • @gomakethings
      @gomakethings  Год назад

      LOL that's just like, your opinion man.
      "It's more efficient to use const..."
      More efficient how?

    • @Killyspudful
      @Killyspudful Год назад +1

      @@gomakethingsI believe the idea with 'const' is that is provides a guard against *accidentally* redeclaring a variable later on in your code, a mistake which was always easy to do with 'var' (because it can be done from anywhere in scope), and a bit harder with 'let' (but not impossible). In general I agree with @ryanthickett above - but if you're confident enough in your patterns that you don't need the extra safety, I can see your point, Chris.
      I think this kind of issue is much more of a potential pitfall in a codebase that a bunch of devs are working on together - if it's really just you, you're more likely to be familiar enough with the code to be able to ignore it...
      Although I have no intention whatsoever of transitioning to React, or Angular, or anything of the sort :)

    • @gomakethings
      @gomakethings  Год назад +1

      @@Killyspudful Oh that's for sure the idea. My argument is that it generally doesn't do much for most people in most code bases, but does add more mental overhead when doing simple things like defining variables.