JSFiddle - React, Tailwind, and code Playground

JavaScript

function getCountry(access_token, country, callback){
    var countryId;
    var query={
            need_all: 1,
            access_token: access_token,
            count: 1,
            code: country
        }
        $.ajax({
            url: "https://api.vk.com/method/database.getCountries",
            dataType: "jsonp",
            data: query,
            success: function( data ) {
                countryId = data.response[0].cid; 
                console.log(countryId); //печатает всё верно, например 1 для 'RU', 19 для 'AU'
                callback(null, countryId)
                return countryId;
              
              },
            error:function(){
            	callback('something wrong', null)
                console.log("Something went wrong");
            }
        });
    return countryId;
}
// call foo
getCountry (yourToken, yourCountry, function(err, success) {
	if (err) {
  	console.log('wtf')
  } else {
  	console.log('my country is', success)
  }
})