"prevButtonState is undefined" error

URL of experiment: http://pavlovia.org/ps2/envelopes

Description of the problem:
I created the skeleton of a new experiment in the Builder, and received the titular error when trying to run it online for the first time. There is nothing fancy in the experiment—text, polygons, and mouse responses only—and no code components. “prevButtonState” was declared before the line where the error arose. I “solved” the error by simply editing the js code to give prevButtonState a value (i.e., “prevButtonState = 1”) after its initial declaration, and now the experiment is running fine, but as the behaviour seems strange I thought it worth mentioning here anyway in case it indicates a larger problem.

The relevant code is as follows:

var prevButtonState:
// putting prevButtonState=1; here circumvents the error.
var continueRoutine;
function consentRoutineEachFrame() {
…
  if (consMouseResp.status === PsychoJS.Status.STARTED) {
    let buttons = consMouseResp.getPressed();
    if (!buttons.every( (e,i,) => (e == prevButtonState[i]) )) { // This line gives the error
…
    }
…
  }
…
}

(Even though the error is no longer a problem for me, I’d be curious to know why it occurred in the first place!)

Try this

Ah, I should’ve mentioned that the above is the js code itself, not something inside a code component in Builder. So, removing var would simply lead to a different error (reference error rather than type error) in this case, since the variable is not otherwise defined. Thanks for the suggestion though!