r/GoogleAppsScript • u/eltostito191 • Jul 19 '22
Question How do you declare your variables?
Var? Let? Const?
I see a lot of examples using var, but my understanding is that let and const are the preferred statements for “modern” JavaScript… or so my udemy course told me.
Are there Apps Script specific reasons for var, or is it just convention.
5
u/fieldyfield Jul 19 '22
I use const unless there's a specific case where I want the script modifying a var as it runs, usually to do with the logic of a for loop.
5
u/dimudesigns Jul 19 '22
There is no reason to use var anymore since the GAS runtime was upgraded to V8. A lot of legacy code still use it, but it's better to avoid using it in your projects now that GAS supports let and const.
4
6
u/elcriticalTaco Jul 19 '22
I use var. The reasoning is simple: Anything else is wrong and ruins my beautiful spaghetti dinner.
0
6
u/burkybang Jul 19 '22
I use const and let. I also use TypeScript.