3 ms·
Seriously though... do you guys declare variables with var or let? I thought let was the new standard for scoping reasons. I'm not trying to start a holy war,
by Timpy 8y ago
Seriously though... do you guys declare variables with var or let? I thought let was the new standard for scoping reasons. I'm not trying to start a holy war, I'm just a junior looking to learn.
- strken 8y agolet and const are good practice in code that will be transpiled, or in Node.js, but they're newish features that don't have 100% browser support yet, so they shouldn't be used if your code has to run directly in a browser. https://caniuse.com/#feat=let https://caniuse.com/#feat=let
- gnode 8y agovar is maximally compatible with older browsers. let and const are more tightly scoped, and that can help you write more maintainable code. I think maintainability was not a first class concern in the writing of this script (consider the terse naming of variables), but it doesn't really matter; it's short, and you can understand it all because there's not all that much to understand. It does the job, and works everywhere.
- kowdermeister 8y agoconst. I always use const and if I need to mutate a variable, then let. var is pretty much just for legacy codes. Yes, it has unique behaviors, but better stick to the new keywords, can prevent some headaches.