I'd like to update the global variable 'barryPosX' to the current position of '#barry'. I am aware that this can be done under the jquery animate function, but since I want to be able to use the barryPosX variable outside the animate function like so...

barryPosX is already in the global scope, so you can just assign the value to barryPosX directly in the getCurrentPos function just like you've done. You don't need to assign the value to barryPosX from within the animation callback.

If you wanted, you could also pass the value into the getCurrentPos function like so: