JSFiddle - React, Tailwind, and code Playground
JavaScript
var test = "";
var img = new Image();
img.src = 'https://developers.google.com/search/docs/data-types/images/recipes01.png';
img.onload = function () {
test = "Sam";
console.log("test = " + test); // Will output test = Sam
}
console.log("test = " + test); // Will output blank string