Given this Google Apps Script script:
'use strict'
const foo = 2;
function bar() {
Logger.log(foo + 2);
}
Running the function bar
results in a TypeError: redeclaration of const foo.
Why? How is foo
being redeclared?
Given this Google Apps Script script:
'use strict'
const foo = 2;
function bar() {
Logger.log(foo + 2);
}
Running the function bar
results in a TypeError: redeclaration of const foo.
Why? How is foo
being redeclared?
Seems like it's due to spotty implementation of ES6. I still get the error if I remove foo from the function, so the error is coming from the global const declaration. The below code produces the same error, but no error if you comment out const foo.
See Google Apps Script Javascript Standard Support, in particular the first comment.
From Apps Script const scoping problems
From the same source
To read the primary source go to https://developers.google.com/apps-script/guides/services/#basic_javascript_features