The MDN tutorial for JavaScript says
Back when JavaScript was first created, there was only
var
. This works basically fine in most cases, but it has some issues in the way it works — its design can sometimes be confusing or downright annoying. So, let was created in modern versions of JavaScript, a new keyword for creating variables that works somewhat differently tovar
, fixing its issues in the process.
It continues to say
For these reasons and more, we recommend that you use
let
as much as possible in your code, rather than var. There is no reason to usevar
, unless you need to support old versions of Internet Explorer with your code (it doesn't supportlet
until version 11; the modern Windows Edge browser supports let just fine).
I'm looking at JavaScript code in templates and tutorials and, almost universally, I see var
for initializing variables.
Are the differences over-stated between var
and let
?