Discussions
Stay up-to-date with the latest news from NetSuite. You’ll be in the know about how to connect with peers and take your business to new heights at our virtual, in-person, on demand events, and much more.
Now is the time to ask your NetSuite-savvy friends and colleagues to join the NetSuite Support Community! Refer now! Click here to watch and learn more!
Behavior of "const" block-scoped variables in SuiteScript
When using a block scoped variable via "const", the scope seems to be ignored in for loops, causing object references to be re-used. Is this intentional?
var output = [];
for(var x = 0; x < 3; x++)
{
const testvar = { val: 1 };
output.push(testvar.val);
testvar.val = 2;
}
Expected: [1, 1, 1]
Actual: [1, 2, 2]
Tagged:
0