First, three useful things about const
(other than the scope improvements it shares with let
):
Your questions:
When is it appropriate to use
const
in place ofvar
?
You can do it any time you're declaring a variable whose value never changes. Whether you consider that appropriate is entirely down to your preference / your team's preference.
Should it be used every time a variable which is not going to be re-assigned is declared?
That's up to you / your team.
Does it actually make any difference if
var is used in place of
const` or vice-versa?
Yes:
var
and const
have different scope rules. (You might have wanted to compare with let
rather than var
.) Specifically: const
and let
are block-scoped and, when used at global scope, don't create properties on the global object (even though they do create globals). var
has either global scope (when used at global scope) or function scope (even if used in a block), and when used at global scope, creates a property on the global object.