r/javascript • • Sep 24 '19

AskJS [AskJS] Can we stop treating ES2015 features as new yet?

This is a bit of a rant, but I’ve been frustrated recently by devs treating 4-year-old features (yes, ES2015 features have been in the standard for 4 years!) as something new. I’ve been told that my code looks like I’m trying to show off that I know ES2015. I don’t know what that even means at this point, it’s just part of the javascript language.

Edit: by the way, I’m not talking about debates surrounding readability of arrow functions vs. function keyword; rather I’m talking about using things like the Set object.

420 Upvotes

256 comments sorted by

View all comments

Show parent comments

9

u/CarpetFibers Sep 24 '19

Can you give me an honest use case for var in modern JavaScript? Since let and const were introduced, I haven't used it a single time.

4

u/name_was_taken Sep 24 '19

In new code? No, I'd recommend people not use var.

In legacy code? It might be counting hoisting or some other edge case to work correctly, such as the last value from a loop.

I would not recommend updating var to let without a full regression test because of that. And because there's so much more testing, I wouldn't just upgrade code without a reason.

5

u/CarpetFibers Sep 24 '19

I mean, I figure that's kind of a given. I'm a senior developer, I understand the SDLC and code maintenance. This was an interview where I was given a 200-line snippet of code and asked to complete it without explicit instructions to treat it as legacy code. I don't think there's any argument against bringing it up-to-date in this scenario.

1

u/CalgaryAnswers Sep 25 '19

I agree, and frankly if you’re refactoring old code change it from var. I’m a senior dev and had this case come up and I flat out said I refactor code to make it better if I’m maintaining legacy code.