Or is it that let doesn't add any real benefit in this case - and it is noisier as it requires a separate line of code just for the declaration.
And I don't understand what you mean with "will break if I cover everything with ES6 block scope".
they whole problem if the hoisting of var. Block Scope is safer in your daily programming. Why to I need to care of hoisting.?
try{varsomething=createSomething();// something is now available in the whole function / global}finally{if(something)something.freeResources();}
You only need to free resources when you doing something you don't wan't anything to access it later. The garbage collector will do the rest for you. So this example is shit. If you know how to program without side effects there is no real case you would go into this.
var could causing side effects if you don't carefully watch that you don't need it in the function. It has no benefit except you call hoisting one. So you want hoisting. And in my opinion (because that's all here) its shit.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Or is it that
let
doesn't add any real benefit in this case - and it is noisier as it requires a separate line of code just for the declaration.And I don't understand what you mean with "will break if I cover everything with ES6 block scope".
var
can be scoped with IIFE, unless you expect scope leak.let
andconst
can be scoped with just{}
alone.One line of code doesn't matter that much (unless TypeScript - you need to and
let
type declaration).I don't want to see this kind of bug.
If that is an issue, an entirely different conversation is necessary: Why is this type of code running in the Global Scope?
var
is constrained (does not leak) within functions and within modules - so nothing about ES2015 or ESNext will make code that usesvar
"break".f(m)
going to get undetected given thatm
is going to beundefined
?m
?m
anyway - likely two different names are more intention revealing.In the majority of cases
let
andconst
are better - but that doesn't mean all cases.they whole problem if the hoisting of var. Block Scope is safer in your daily programming. Why to I need to care of hoisting.?
You only need to free resources when you doing something you don't wan't anything to access it later. The garbage collector will do the rest for you. So this example is shit. If you know how to program without side effects there is no real case you would go into this.
var could causing side effects if you don't carefully watch that you don't need it in the function. It has no benefit except you call hoisting one. So you want hoisting. And in my opinion (because that's all here) its shit.