Hi Sunshine,
Not a direct answer to your question but some context as to why JS has three ways of declaring a variable (var, let, const).
Remember Ramon said the JS was created in a couple of weeks about 25 years age and “var” was in the language from the beginning. As JeffScript said in a previous post - “let” and "cons"t were not added in until ES6 was released in 2015. So why do we need three ways of doing the same thing?
Well a lot has changed since 1995. The HTML and CSS languages have evolved greatly since then, the web has expanded onto to devices that we could only dream of (phones, smart phones, tablets, watches) and the worldwide web itself has assumed a larger and more important role in all our lives - not just as an information sharing service but as a way of doing many of the basic things that we need to do to live our lives (shopping, telemedicine, registering to vote, banking, etc). As such writing robust, less buggy software in not just important it is vital! So the language has to keep up. As previous commenters have noted “let” will throw an error if you try to redeclare a variable (which, among other things, makes it more difficult to mess things up if more than one programmer is working on a project. A “const” can’t change its value and - again - will throw an error if you try to change it. There are times when this is incredibly useful (again particularly on larger projects).
So that explains why we have new keywords for declaring variables, but why keep “var” around - why not just get rid of it? Well, the keepers of the JS language standard are committed to extreme backwards compatibility - in fact the very first JS program ever written and released on the web will still run today in every modern browser. Think about it - if your online banking software suddenly stopped working because “var” was no longer recognized our lives (as users) would be chaos (as programmers we would probably have a lot more work - but going into old code and changing “var” to “let” or “const” would, for me anyway, be incredibly boring.)
The reverse problem does come up. People are forced for some reason to use older browsers that can not run modern javascript. There is a good article about it at: The Optional Chaining Operator, “Modern” Browsers, and My Mom - Jim Nielsen’s Blog and it’s worth the read.
So yeah, we have to learn about “var” (because we’re going to see it in legacy code) as well as “let” and “const” because that’s the way we write code today and no doubt we will have to learn (relearn) many more things, because just when you think you know something in a programming language…something new comes along.
Welcome that’s the world we live in (and I, for one, love it.)