This code checks if exist a image or not.
Inside the function onload I would like to change the variable 'control' with a boolean value.
var control = 'a.jpg';
var image_name = control;
var image = new Image();
image.onload = function() {
control = true; // Why this change does not happen outside of this function?
};
image.onerror = function() {
control = false; // Why this change does not happen outside of this function?
};
image.src = image_name;
console.log(control); // The value is not changed in a boolean
But outside the function, the variable is not changed. Why?
Thanks