I am having a scope issue.
function boo() {
    var ajax5 = new XMLHttpRequest();
    ajax5.onreadystatechange = function() {
        if (ajax5.readyState == 4) {
            xxx5 = (ajax5.responseText);
            var obj = JSON.parse(xxx5);
            d2 = obj.myvariable;
            return d2;
        }
    };
    ajax5.open("GET", "URL TO SCRIPT (CORS HEADERS ENABLED)", true);
    ajax5.send(null);
};
var xxx = boo();
If replace return d2 with console.log(d2) I get the value in console.
With return d2; I get undefined.
I want xxx to hold the value of d2.
 
    