One of the key things that V8 has sorted out is the scope of variables. Using var to declare variables meant that anything declared within the scope of a function could easily be accidentally overwritten, causing hard to track down errors. ES6 (since it’s commonly known as V8 in Apps Script – I’ll be referring to it as V8 from now on), has added const and let to the variable declaration vocabulary to help prevent these kind of problems.
With the introduction to the new Google Apps Script V8 runtime new opportunities are available for writing clean and robust code in the script editor using modern JavaScript syntax. In this post from Bruce Mcpherson you can learn some of the basics of var
, const
and let
.
Source: JavaScript V8 variable scopes – Desktop liberation
Member of Google Developers Experts Program for Google Workspace (Google Apps Script) and interested in supporting Google Workspace Devs.
The link (https://ramblings.mcpher.com/google-apps-scripts-snippets-2/apps-script-v8/javascript-v8-variable-scopes/) has now moved to (https://ramblings.mcpher.com/apps-script/apps-script-v8/javascript-v8-variable-scopes/)
Thanks Michael 👍🏻