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