Thilip 0 Newbie Poster

I try to get facebook id when like button pressed, the function alerts Id, but when I retrun value it says undefined. Here is my code

window.fbAsyncInit = function() {
FB.Event.subscribe('edge.create', function(response) {
    //ajax code to be added for like system
    usr_id = checkLoginState(); 
    alert(usr_id);// this returns undefined 
    console.log(usr_id);


});

// Code to detect clicking unlike
FB.Event.subscribe('edge.remove', function(href) {
    //ajax code to be added for unlike system
    //fb_count_updater('1');
    usr_id = checkLoginState(); 
    alert(usr_id);
    console.log(usr_id);



});
};

 function checkLoginState() {
 FB.getLoginStatus(function(response) {
 if (response.status === 'connected') {

var uid = response.authResponse.userID;
alert(uid);  // this place returns about correct facebook ID
return(uid); 

} 
});
}