News for hackers. Stuff that matters.
Re:What’s New in ES2019 by heavenlyblue on Tuesday July 30, 2019 @08:30AM (#20564194)
So what's the point of having let, then?
Re:What’s New in ES2019 by rpeden on Tuesday July 30, 2019 @08:39AM (#20564247)
let declares a block-scoped variable, while var declares a function-scoped variable.

Limiting a variable's scope can help avoid subtle and potentially annoying errors. For example, if you use a let variable inside an if block, it'll only be accessible by code inside the block. If you use var inside an if block, your variable will be visible to the entire function.

Re:What’s New in ES2019 by heavenlyblue on Tuesday July 30, 2019 @08:47AM (#20564297)
The truth is that if you need to declare a variable outside your current scope you should probably declare it in the outside scope in the first place.

In the scenario with var/let I need to grok the code in order to tell which variables are visible in my current scope.

Re:What’s New in ES2019 by jarekkruk on Tuesday July 30, 2019 @03:05PM (#20568077)
I tend to mainly use const, let only when necessary. I never use var and set linter to scream about it at me. IE11 supports it, so unless you develop application for IE compatibility mode (my condolences) I don't see a reason to use var. On the other hand var mainly bites you when declaring closures inside loops, also hoisting is just plain weird.
Re:What’s New in ES2019 by z3t4 on Wednesday July 31, 2019 @07:15AM (#20573350)
I find hoisting a convenient feature as I can declare the variable in context to where it's used. It means I do not have to break the flow of how the code reads, making the code easier to understand and less bug prone. Example:

    if(something) var foo = 1;
Re:What’s New in ES2019 by heavenlyblue on Wednesday July 31, 2019 @07:52AM (#20573556)
So how do you maintain the invariant that this variable is used only if <something> is true _down the line_?
Re:What’s New in ES2019 by z3t4 on Wednesday July 31, 2019 @07:54PM (#20579897)
It's only logical that it will be undefined if it's never assigned. With var you can just declare anywhere. While with let it feels like a chore when you have to declare in a parent block, eg. outside the if-block for it to be accessible within another if-block. Lexical function scope works very well in an async language with first class functions, as you deal mostly with functions, which can access it's closures at any time, etc. makes it logical that the function should define the scope, not if-statement or for-loops.
Re:What’s New in ES2019 by z3t4 on Wednesday July 31, 2019 @07:23AM (#20573397)
let also does some magic in for-loops, creating a new variable for each iteration, basically creating a closure.

It also throws and error if it's used before it's declared.

Let basically fix some minor issues that hard-bitten JavaScript developers have learned to avoid.

Re:What’s New in ES2019 by chrisweekly on Tuesday July 30, 2019 @08:38AM (#20564239)
block scope