Using time.ZonedDateTime.now() in JS scripting

if I run the below script once, it works:

let now = time.ZonedDateTime.now()
console.log("Time Check", now)

if I run it a second time I get an error saying “now has already been declared”

Would the same thing be true if I put that script in a rule? Would it error after the first run of the rule?

In the UI, the script is reused from one run to the next. So you cannot use let nor const in the script’s outer context. For example:

let foo = 1; // error on second+ run
const bar = 2; // error on second+ run

if(foo) {
  let baz = 3; // no problems
  const biz = 4; // no problems
}

This is something unique to UI rule script actions and conditions and probably will be addressed at some point. In the mean time use var or wrap the whole thing in a self calling function.

function() {
    // code goes here
}();

or something like that.