News for hackers. Stuff that matters.
Re:JavaScript variables: var and let and const by jakub_g on Friday March 06, 2020 @03:23PM (#22506967)
There's one non-obvious corollary from the fact that using let/const before declaring throws an error and var does not:

If you have let/const in your source code, but you use babel to transform it to ES5, you may have cases where you use let/const in that error-throwing way, but it's compiled down to var, and all is good (apart from variable being undefined when used).

When you however upgrade your babel conf to output ES6 and not compile down to var, you'll be having reference errors in those places, which may explode your app. I learned in production after enabling "differential serving" (module/nomodule).

There's an eslint plugin that can check for this stuff, but it finds false positives in 95% of cases (matter of personal preference - it disallows "valid but not blessed by the authors" behavior), so it's very likely you don't have it enabled, just like us.

Re:JavaScript variables: var and let and const by _bxg1 on Friday March 06, 2020 @03:36PM (#22507084)
Oof. I was surprised for a second that Babel would simply put "var" in there instead, when it expressly doesn't do the same thing. But then I realized that emulating block scope without let would mean wrapping all blocks in anonymous functions, which would carry significant overhead.

Gross.

Re:JavaScript variables: var and let and const by thewarrior on Friday March 06, 2020 @07:52PM (#22508876)
So transpiling down to ES5 doesn’t preserve semantics ?
Re:JavaScript variables: var and let and const by jakub_g on Saturday March 07, 2020 @01:18PM (#22513053)
For some features, having 100% spec compliant behavior in transpiled code would mean excruciatingly slow/bloated code, or be downright impossible. There's a reason why features are added to the language after all: to add things that are impossible or too complex to write in old version of language.

Transpilation is "best effort" and involves some tradeoffs.