I have a script that needs to run multiple times, but I'm unsure if it's the first time running. Therefore, I must check and declare it if necessary:
if (typeof variable == undefined) { let variable = new Set(); }
However,
1.) Re-declaring with let variable;
consistently results in an error
2.) The variable exists only within the 'if' scope
3.) Using the 'let' command requires a full block 'if', ternary operation, or 'bracket-less if'
Is there a way to change the variable's scope? Like how we could do with the trusty old var
? I'm open to using Set but would like to know if this kind of modification is possible. Is there perhaps a 'declare if not declared' command available?