JSFiddle - React, Tailwind, and code Playground

JavaScript

var timelineimgpath;

function foo(userid) {
    return $.ajax({
        url: 'https://graph.facebook.com/' + userid + '?fields=cover',
    });
}

foo("19292868552").done(function (data) {
    /** Do everything you need with your data */
    timelineimgpath = data.cover.source;
    alert(timelineimgpath); // <-- this is called after
});

/** 
 * You see that the data is not available 
 * The Facebook API query has not occured yet!
 */
alert(timelineimgpath); // <-- "undefined"