DEV Community

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

 
lionelrowe profile image
lionel-rowe
if(user) {
  console.log('Welcome, ' + user);
} // ...

let user = 'Vaishali';
Enter fullscreen mode Exit fullscreen mode

The way var is hoisted is yet another unnecessarily confusing thing about it. This would be easier to reason about if the declaration was written at the start and split from the assignment, which would work with let.

you still have to understand how it works to understand code from other sources.

Agree with this. JS devs should definitely learn about var so they can read legacy or transpiled code. Then they should (personal opinion) add a rule to their linter that disallows writing it in their own code.