Set variable to contents of file using fetch in JavaScript [duplicate]

I want to save the contents of a JSON file hosted on the web to a variable so I can access it more easily.

I tried this:

let tempInfo;
const info = (function getInfo() {
    fetch('https://mesure.x10.mx/twelve-of-code/not-an-api/challenges/information.json')
        .then(res => res.text())
        .then(text => {
            tempInfo = text;
        })
    return tempInfo;
})();
alert(info);

… and it just alerts “undefined” each time