I am trying to change the boolean value from true to false and false to true whenever the button is clicked however the value is changing within the function but when I console the value outside the function it is giving the default value that I set during the variable declaration`
var bool = 0;
switchCameraButton.addEventListener('click', function() {
camera.switch();
if(bool == 0){
bool = 1;
}else{
bool = 0;
}
console.log(bool);
});
console.log(bool);
`
I was trying to change the boolean value when ever the button is clicked but the value is not changing i mean it is changing within the onclick function but not outside the function
clickfunction? Theconsole.logfires before the button is clicked. What problem is it that you are hoping to overcome using a global variable? Is it to do with the camera.switch() somehow?