4 ms·
What's so wrong with var? And it's a shame in Swift it's {var, let} vs JS {let, const}! My motivation for learning GraphQL is directly tied to Amplify/AppSync.
by emehex 5y ago
What's so wrong with var? And it's a shame in Swift it's {var, let} vs JS {let, const}!
My motivation for learning GraphQL is directly tied to Amplify/AppSync. It is actually speeding things up for me considerably. Sorry to hear that you haven't had a great time with the tech~
- zzo38computer 5y agoYou can use "var", but it does not have proper block scoping; usually proper block scoping would be wanted, so use "let" instead, or "const" if you do not need to reassign the value later (I don't know whether or not any implementations can optimize based on that).
- dragonwriter 5y ago> What's so wrong with var? var his function scoped, allows redeclarations in the same scope to work as reassignments, and has some other quirks, while let is block scoped and errors on redeclarations in the same scope. The net result is that var is a lot more trouble. If you are using ES6+ and need a reassignable variable, you should use let. If you need something that won’t be reassigned (even if it will be mutated), use const.
- schwartzworld 5y agoLet/const behave more the way you'd expect in JavaScript. They came about as part of the language shift in 2015, along with a lot of other conveniences. Many of JS's warts are less of an issue if you write modern code. I guess there's nothing technically wrong using var, but there's no reason to use it over let in almost any setting, and a tutorial that starts you with var might be outdated.