"const" does not work as expected in JS policy

mohdilyas
Participant IV

I have been using JS policy a lot in case i need to satisfy a use case that can't be done via policies. I had restricted myself to using "var" when it comes to declaring or instantiating variables. Recently, I found that we can use ES6 coding standards in JS policy and I started using "let" and "const" key words and ran into the following problems:

  1. "let" cannot can be used in a JS policy. Compiler throws an error if you try to use this keyword. (Being a big fan of "let" & "const", this was a huge disappointment)
  2. const doesn't scope variables within the blocks (if-else...). I used a variable with "const" in "if" block and then used the same variable name with "const" in else block. Output: "cannot redeclare variable" (this was another shocker)

Please help me to understand, what exactly is happening here? @Dino-at-Google

9857-screenshot-2020-05-07-at-35114-pm.png

0 4 814
4 REPLIES 4

No it doesn't .

the JS policy does not support ES6.

It's EcmaScript 1.7.

No let, const.

No typed arrays

No spread / rest operators

No arrow functions/lambda notation .

I have been using "const" in many JS policies to describe the global variables and it works. Problem occurs when using them inside blocks.

I am surprised! but anyway the JS callout is not ES6.

So you probably need to use var statements, inside blocks.

Yeah I will do that. You can also check, things I said about using "const".