Thanks for the great question. I will try to answer by breaking it down first with var vs let and const
var is function scoped. let and const are block scoped. This is the biggest difference, to use the wise words of a work colleague: "let is what var should have been from the start."
That said the main difference with let vs const is that const does not allow re-declaring. This does tell a developer that it will not change as you mentioned, but more importantly, it is telling your program that it cannot change.
Some linters out there (AirBnB) will throw an error if you declare a let and never change or re-declare it, the error will be to use a const.
I hope I answered your question sufficiently.
Cheers!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Patrick!
Thanks for the great question. I will try to answer by breaking it down first with
var
vslet
andconst
var
is function scoped.let
andconst
are block scoped. This is the biggest difference, to use the wise words of a work colleague: "let
is whatvar
should have been from the start."That said the main difference with
let
vsconst
is thatconst
does not allow re-declaring. This does tell a developer that it will not change as you mentioned, but more importantly, it is telling your program that it cannot change.Some linters out there (AirBnB) will throw an error if you declare a
let
and never change or re-declare it, the error will be to use aconst
.I hope I answered your question sufficiently.
Cheers!