Reading some vuejs 3 with Composition API docs I see 2 possible way of vars declaring, like
const var_name = ref('')
or
let var_name = ref('')
and looks like var declared with “const” can be modified(say getting data with axios request). I do not see any errors when I use similar code inb my app.
Are these declarations the same? Which way is preferable?
CodePudding user response:
I think an article like this is still the best way to go here: https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/
As of what is recommended, usually use const
and if you need to redefine something else on top of it, use let
. Of course, non primitive types (like Objects) can be mutated, it being out of the const
scope redefinition.
TLDR: this is more of a JS vanilla question and have nothing to do with Vue or Composition API in particular.