[In case you don't know, in ECMAScript/JavaScript, variables declared with var have global or function-level scope, and variables declared with let have block-level scope.]
Lately all the code-quality folks and linting tools are saying "use let instead of var," but I can't think of a situation where using let instead of var makes any real difference. Plus there are plenty of situations where you have to use var.
I will grant that using let can help beginner programmers avoid certain kinds of bugs, but so can writing code with better style. Examples:
Otherwise, this is my contention:

via Imgflip Meme Generator
Lately all the code-quality folks and linting tools are saying "use let instead of var," but I can't think of a situation where using let instead of var makes any real difference. Plus there are plenty of situations where you have to use var.
- Need a global variable? Then you need to use var. (Or const, if you want to prevent reassignment.)
- Need a variable that will be modified in a loop and then used outside the loop? Then you need to use var.
- Need to use the same variable name both inside and outside of a function while giving them different scopes? var already does that, so using let makes no difference.
- Need to reference a variable before it's declared? Then you should probably restructure your code so that you're not doing that in the first place, because it's usually bad style.* But leaving aside questions of style, if you're relying on hoisting, then you need to use var.
- Need to declare and initialize a variable in the middle of the function, immediately prior to using it, because it's easier to understand the code that way? Then there's no difference between using var or let.
- Need to use the same variable name several times in a bunch of nested if-statements, and you want them all to have different scopes? Then you need to use let. BUT WHY DO YOU NEED TO DO THIS? Why can't you use different variable names? Wouldn't it be more confusing, not less, to see the same variable name declared several times?
I will grant that using let can help beginner programmers avoid certain kinds of bugs, but so can writing code with better style. Examples:
- If you always declare variables before using them, then let's non-hoisting behavior is superfluous.
- function foo() { x = 5; } — Initializing a variable inside a function without a keyword gives the variable global scope. But if you always initialize variables with var, then you can't accidentally create global variables, and so let's implicit protection against that sort of thing is superfluous.
Otherwise, this is my contention:

via Imgflip Meme Generator