Issue with while loop in javascript but not python

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 2021.2.3
What are you trying to achieve?: In my experiement, I have a “does not apply” checkbox that changes to the red color if you click on it. I would like in case of a miss click give the possibility to change the checkbox to its initial color (white) by clicking a second time on it.
I have added some lines of code in the “Each Frame” section and I my goal was to wait that the mouse button is released before giving the opportunity to click on the checkbox again. Below is the portion of code working in python and then the portion of code not working in javascript.

Working in Python:

clickable=Unknown

mouse_pressed = False
if unk_mouse_3.isPressedIn(clickable):
    clicked_things.append(clickable.name)
    mouse_pressed = True

if clickable.name in clicked_things:
        clickable.fillColor = 'red'
        isred=1
    
while mouse_pressed == True:
    
    if not unk_mouse_3.isPressedIn(clickable):
        mouse_pressed = False

if isred ==1 and len(clicked_things) > 1:
    clicked_things=[]
    clickable.fillColor = 'white'
    isred=0

Not working in Javascript

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
clickable = Unknown;
mouse_pressed = false;
if (unk_mouse_3.isPressedIn(clickable)) {
    clicked_things.push(clickable.name);
    mouse_pressed = true;
}
if (_pj.in_es6(clickable.name, clicked_things)) {
    clickable.fillColor = "red";
    isred = 1;
}
while ((mouse_pressed === true)) {
    if ((! unk_mouse_3.isPressedIn(clickable))) {
        mouse_pressed = false;
    }
}
if (((isred === 1) && (clicked_things.length > 1))) {
    clicked_things = [];
    clickable.fillColor = "white";
    isred = 0;
}

I have tried a bunch of alternatives none of them were working as I would like. Basically the issue was often the same, that is the code remains stuck in the while loop without leaving the loop even though the mouse state changed. I have finally use another solution that is in my opinion not conventional but at least that is working. In any case I am still curious about any solution based on the javascript code above and allowing to wait for a mouse change state. Finally, just to say that I am not really familiar with both python and javascript, so one of the reason I am also asking is too learn to better code with these two languages.

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
clickable = Unknown;

state_mouse=unk_mouse_3.isPressedIn(clickable);

if (unk_mouse_3.isPressedIn(clickable)) {
    clicked_things.push(clickable.name)
    }

if (_pj.in_es6(clickable.name, clicked_things) && (isred === 0)) {
    clickable.fillColor = "red";
    isred = 1;
    console.log("within red")
        
    n=0;
    while (n < 1000){
        n++;
        release=1;
        console.log("within loop red")
    }
    clicked_things=[];
}



if ((_pj.in_es6(clickable.name, clicked_things)) && (isred === 1)) {
    clickable.fillColor = "white";
    isred = 0;
    console.log("within white")
        
    n=0;
    while (n < 1000){
        n++;
        release=1;
        console.log("within loop white")
    }
    clicked_things=[];
}