let/const actually enforce block scope, whereas var hoists to the top of the function. If you take a look at transpiled code meant for compatibility, it becomes clearer (I'm doing this by hand for readability):
I could have it slightly wrong, but back when they introduced the new keywords, this is how I remember it being explained to me. Tbh it was this that got me to switch over from CoffeeScript.
EDIT[1]: I had it wrong, like I thought. The code is better edited to reflect it.
EDIT[0]: fixed the function name, and also an article from last year that explains it:
View all comments
Show parent comment
12
u/leo848blume Jan 01 '22
What does 'let' actually do differently?