Monday, September 23, 2019

Can let replace var in JavaScript?




I'm from a Java background and started learning JavaScript.



Declaring variables in JavaScript using the keyword let sounds like is uses similar scope rules of declaring variables in Java. The concept of hoisting in JavaScript is confusing (consider my C++/Java background) and I don't see any pitfalls in using let in place of var.



Is my understanding correct?


Answer



Yes, your understanding is correct.




Some experts even recommend solely using let everywhere, if it is available in your environment (Douglas Crockford said it in his Pluralsight course JavaScript the Good Parts).



ESLint even has a rule not to use var in ES6 Environments.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...