DEV Community


Discussion on: Stop using var for declaring variables !!!

larsonnn profile image
Lars Feldeisen

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 {
  var something = createSomething(); // something is now available in the whole function / global
} finally {
  if (something) something.freeResources();
Enter fullscreen mode Exit fullscreen mode

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.

Thread Thread
bryonmapes profile image
Bryon Mapes

I'm not personally a fan. I would rather use block scope with let.