can i use const in 1.0?
# suitescript
e
can i use const in 1.0?
s
No, let and const were introduced in ES6
c
Shouldn't be writing any new 1.0 code anyways honestly. Should take the time to re-write in 2.0 if applicable. Otherwise you're starting off with bad technical debt or using an outdated api.
e
'let' crashes 'const' works
b
you can use const, but it wont behave to javascript specifications
e
what do you mean, example
b
its not block scoped
reassignment attempts do not throw errors
a
In other words it does the exact same thing as a var in your case, so just use var
b
it does prevent redeclaration
and const cant be reassigned, though it wont throw errors if you try
c
1.0 code though is the root of it
don't write 1.0 code
b
has the same behavior in 2.0
c
How bad does code have to be that you're re-assigning a const though either way?
b
usually you use const when you dont want others changing your values
s
write 2.1 code
b
if those people try anyway, they see weirdness with the const not changing, which is harder to debug if they dont know its a const and how const is not the javascript const
c
You can still change the values of the const you just can't re-assign it. You'd have to Object.freeze it to make it totally locked down
b
Copy code
const x = 5;
x = 6
log.debug('x', x)
will log 5
c
const myTestObject = {x: 5}; console.log(myTestObject.x); myTestObject.x++; console.log(myTestObject.x);
s
and of course, typescript would error before you even deploy the code. So
write 2.1 code and TypeScript
c
logs 6
b
thats the same behavior you get in javascript
mostly because it isnt reassignment of myTestObject
there is a reason im being very specific in my use of the word reassignment instead of change
c
"usually you use const when you dont want others changing your values"
Thats just not true. Its the idea but its not how its implemented
s
battk's code should throw a runtime error in SS2.1
b
correct, but you using const wouldnt help anyways
s
creece's code is just demonstrating how js does const.
c
I think we all 3 get it
i use const all the time and just let it be the "normal" const and not try to overwrite it.
s
creece, did you suggest using SS2.0 on purpose, i.e. avoiding SS 2.1? I can't remember the last time I created a 2.0 script?
c
im just used to saying 2.0
s
that's what I figured