I'm surprised by the state of const/let nowadays. The well-known good practice: use const by default; use let when it's needed. At the release of ES6, it was the way to go. But everyday I notice libraries—and some really famous— that use let everywhere in their docs, or some really influent developers from Google or Facebook who share samples of code on Twitter using let when it's not needed [1]. I don't know why. Se…
It also doesn't help that let is 3 letters versus const is 5; programmers if anything will default to the faster to type option.
Overview of JavaScript ES6 features
61–70 of 250 posts
Re: Overview of JavaScript ES6 features
#62Earlier quoted context omitted.
I resisted const for like 10 minutes. You get used to it really quickly and then when you see a 'let' in your code you just know something is happening with that variable afterwards. When I have to go back to programming in a language without const declarations it feels bad.
I know I should use const. I lazily leave it until the end then try to shoe-horn it in. Then it ripples through the code until I give up. Then I hate myself.
I think running eslint --fix will even change your "let"s to "const"s where appropriate, but don't quote me on that.
Re: Overview of JavaScript ES6 features
#63Earlier quoted context omitted.
For anyone who wants to use ES6 in production, https://babeljs.io/ is amazing.
It's both amazing, and 600MB worth of dependencies. We use it for server-side code. It's high quality, and we only have a few issues with it, but I can't wait to be able to ditch is (pretty much when async/await lands in a stable node).
Re: Overview of JavaScript ES6 features
#64Earlier quoted context omitted.
Also - for anyone writing code where performance matters, the question isn't when browsers support the syntax, it's when each JS engine's optimizations support it. E.g.: until some months ago just putting "let foo" into a function would cause V8 to bailout (meaning the whole function gets executed slowly, even if the actual let statement gets removed as dead code). Unfortunately I've never found any good references o…
This is a real concern, but it definitely carries the usual caveats about premature optimization and needing to measure regularly to confirm that it is a real concern and that the performance landscape hasn't shifted since the last time you measured it. The best suite I've seen is https://kpdecker.github.io/six-speed/ which measures node and the various modern browsers which Sauce Labs supports and appears to be run…
Re: Overview of JavaScript ES6 features
#65While I'm a big believer in most of the ES6 changes (arrow functions! let/const! classes! generators!), I am not a big fan of many of the new destructuring features. They can actually make your code less approachable if you don't already know what's going on.
Re: Overview of JavaScript ES6 features
#66var's function scope is a feature! You don't have to place variable declarations in the header! (they are hoisted) Placing the var declarations where they are used makes the code easier to understand. The point of constructor functions is not having to write new . So classes does nothing besides syntactic sugars over the prototype system, witch actually makes it more complicated and the code harder to maintain. Async…
Re: Overview of JavaScript ES6 features
#67Re: Overview of JavaScript ES6 features
#68Earlier quoted context omitted.
Promises and callbacks have fundamentally different behavior. Promises are much more reliable (only executed a single time, always executed asynchronously vs possibly synchronously, etc.) and also have slightly different execution behavior in the event loop. People emphasize the syntax differences, but that's not the most useful thing about Promises imo. You Don't Know JS's async book has an excellent in-depth writeu…
The function passed to the promise is executed synchronously, the call to `then` is always asynchronous.
Re: Overview of JavaScript ES6 features
#69Re: Overview of JavaScript ES6 features
#70Earlier quoted context omitted.
I don't think anything in the rest of their comment has anything to do with block scoping vs function scoping. I do understand the technical difference very well - I have a PhD in implementing programming languages with function scoping like JavaScript. If you agree with the person I was replying to maybe could you humour me and explain why you think function-scoping var is a useful feature?
> I do understand the technical difference very well - I have a PhD in implementing programming languages like JavaScript. I am happy for your PhD and that it is for implementing programming languages like JavaScript. My assertion is the advantage of having function scoping is apparent to those who understand function scoping. Block scoping-style programming in JavaScript was always, in my experienced, shoe-horned in…
I assert that if you can't say what the advantage is then you don't understand it yourself.
"You'd see the advantages if you understood this, and since you don't you must not understand it" is not a reasonable thing to say to people.