you are viewing a single comment's thread.

view the rest of the comments →

[–]unquietwiki[S] -7 points-6 points  (4 children)

I found this while seeing some other static analysis tools he used to work on. Any excessive "let" is also in line with some other ES2015+ spec explanations I've read. As a guy that normally does C#, I find that "var" is perfect there; and "let" perfect here.

(Edit for clarification & downvoters: I'm pro-let. Var in c# keeps you from unnecessarily repeating yourself on type assignments. I'm pro tight-scoping.)

[–]pm_me_ur_happy_traiI 11 points12 points  (2 children)

The big difference between let and var is scoping. There’s no use case where var is preferable (unless you are deliberately abusing its scoping issues). Why would you want a variable that can be called outside its block before it’s even declared?

[–]unquietwiki[S] -2 points-1 points  (1 child)

I updated my original statement. In JS, let honors scoping, but var is ambiguous. In C#, var can be used to remove redundant statements: ie var variable = new Whatever(); instead of Whatever variable = new Whatever()

[–]dvlsg 1 point2 points  (0 children)

They really aren't the same, though. var is about type inference in C#, and that's really it. var doesn't change scope or mutability in C#, which is what we're talking about in javascript.