How to prevent the js listener from automatically declaring variables each time?

map.addEventListener("click", function(e){
    var onclick=0;
    if(onclick%2==0){
        onclickPP;
        var myP1 = new BMap.Point(e.point.lng,e.point.lat); 
        alert("onclick="+onclick);
        alert("" + e.point.lng + ", " + e.point.lat);
    }
    else{
        onclickPP;
        var myP2 = new BMap.Point(e.point.lng,e.point.lat); 
        alert("" + e.point.lng + ", " + e.point.lat);
        driving2.search(myP1, myP2);    //
        alert("onclick="+onclick);
        alert((map.getDistance(myP1, myP2)).toFixed(2)+" "); 
        }
    });
Does

redeclare onclick=0 every time the listener calls? But I write the declaration outside the listener and print the value of onclick for null,. What can I do to prevent me from declaring onclick? every time the listener is called?

Mar.10,2021
Menu