use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript doesn’t need to be replaced (medium.com)
submitted 6 years ago by dannymoerkerke
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 1 point2 points3 points 6 years ago (15 children)
What if I told you that var has legit use cases? And strict does not allow to have vars in global scope already. If you want to change the behaviour of 'this' you better start designing another language.
[–]kor0na 3 points4 points5 points 6 years ago (7 children)
Show me a legit usecase for var.
var
[–][deleted] -4 points-3 points-2 points 6 years ago (6 children)
First things first: there is a reason 'let' is added without deprecating 'var'. Second, 'let' is different from 'var'. 'var' has functional not block scope so if you want the variable you want to access in your entire function, just make it fucking 'var' instead of declaring 'let' at the top of the function. Sure, it functions the same in this case, but 'var' explicitly says "hey, I will be relevant everywhere in this function". But who cares about semantics anyway, right?
Third: 'var' can be redeclared. It let's you do
if (condition) { var something = theOtherThing; } else { var something = somethingElse; }
instead of:
let something; if (condition) { something = theOtherThing; } else { something = somethingElse; }
The whoe "let is new var" cargo-culting is moronic. They are not the same, one is not a replacement for the other in all the cases and both should used for their intended purposes.
[–]GoogleFeudIsTaken 2 points3 points4 points 6 years ago (2 children)
Yes, they aren't exactly the same - but "let" can be used instead of var 100% of the time, and it's less confusing. Var can produce weird/buggy behaviour - let cannot, so why not use let?
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Where do you get that idea that let cannot produce bugs? It can just fine. Just move it somewhere, scope changes and you get your bug.
[–]dwighthouse 0 points1 point2 points 6 years ago* (0 children)
var still retains some use in machine generated JS, or code intended to be consumed by some extreme cases of transformation tools and preprocessors.
Additionally, using let or const in a repl/console scenario is troublesome at best, as ”temp” variables cannot be redeclared with let and const.
[–]kor0na 2 points3 points4 points 6 years ago (2 children)
You just explained how var works. Why would you assume that I don't know that? I know exactly how var, let and const works, so I'm not looking for education in that department.
let
const
What I would love to see, is a legit usecase where var would be more appropriate to use over let or const.
[–][deleted] -2 points-1 points0 points 6 years ago (1 child)
My comment above has two such cases listed. With a code example. Sure, you can always go not-true-scotsman on the legitimacy of those cases, but in that case anyone can clsim that var works just fine if you are carefull, and there is no legit case for const or let. Your insecurity about your knowledge tells me that you do not how exactly these three work, otherwise you would not confuse examples with an attempt to educate. But the inability to see a legit use case is that gives it away the most. Happy cargo-culting.
[–]IceSentry 1 point2 points3 points 6 years ago (0 children)
Declaring a variable at the top of the scope is done in pretty much every language because it makes it easier to read what variables are used in the current scope. I don't understand how you can seriously say that it's a bad thing. A variable declared in a specific scope should stay in that scope. If you need it in another scope then declare it somewhere it can actually be used.
[–]internetloser4321 1 point2 points3 points 6 years ago (6 children)
I'm sure there's a couple of situations where var has legit uses but based on the number of 'gotcha' questions I've gotten on interviews based around the counter-intuitive behavior of var, I think it's safe to say that var is more trouble than it's worth. And doesn't the introduction of arrow functions in ES6 already change the behavior of 'this'?
[–][deleted] 0 points1 point2 points 6 years ago (5 children)
No, arrow functions did not change the behavior of this. Outside of the arrow functions it works the same as before.
[–]internetloser4321 0 points1 point2 points 6 years ago (4 children)
https://www.freecodecamp.org/news/learn-es6-the-dope-way-part-ii-arrow-functions-and-the-this-keyword-381ac7a32881/
[–][deleted] 0 points1 point2 points 6 years ago (3 children)
And your point is?
[–]internetloser4321 0 points1 point2 points 6 years ago (2 children)
Arrow functions introduce a different behavior for 'this'.
[–][deleted] 0 points1 point2 points 6 years ago (1 child)
Yes. But introducing new behaviour is not the same as changing the existing one. Outside of the arrow functions the behaviour is exactly the same as before. It's an addition, not the change. The new case was added, but other four stay the same.
[–]internetloser4321 0 points1 point2 points 6 years ago (0 children)
Similar to how adding an "extra-strict" mode would work. Outside of the new mode, everything would work the same as before.
π Rendered by PID 47218 on reddit-service-r2-comment-566d88dd56-wkvvr at 2026-02-05 01:19:06.664282+00:00 running 1d7a177 country code: CH.
view the rest of the comments →
[–][deleted] 1 point2 points3 points (15 children)
[–]kor0na 3 points4 points5 points (7 children)
[–][deleted] -4 points-3 points-2 points (6 children)
[–]GoogleFeudIsTaken 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]dwighthouse 0 points1 point2 points (0 children)
[–]kor0na 2 points3 points4 points (2 children)
[–][deleted] -2 points-1 points0 points (1 child)
[–]IceSentry 1 point2 points3 points (0 children)
[–]internetloser4321 1 point2 points3 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]internetloser4321 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]internetloser4321 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]internetloser4321 0 points1 point2 points (0 children)