JSFiddle - React, Tailwind, and code Playground

JavaScript

//My variable ///////////////////////////////////////////
    var foo = "";
    
    //Send request //////////////////////////////////////////
    $.ajax({
        url: "/",
        dataType: "text",
        success: function(response) {
            foo = "New value:" + response;
        },
        error: function() {
            alert('There was a problem with the request.');
        }
    });
    
    //Alert updated variable ////////////////////////////////
    alert(foo);