I think this might be related:
Tl;Dr: JavaScript only have global scope and function scope with the var
keyword, to have block scope you need to use let
instead.
Not sure which ecmascript version jsscripting uses, but if let
is not available you should be able to move the declarations to the timer body.