JSFiddle - React, Tailwind, and code Playground
JavaScript
var control = 'a.jpg';
var image_name = control;
var image = new Image();
image.onload = function() {
control = true;
after();
};
image.onerror = function() {
control = false;
after();
};
image.src = image_name;
function after(){
alert(control);
console.log(control);
}