What is the best to use global variables outside of a callback function?
var icon;
$(function(){
$.get(\'data.xml\', function(xml){
The problem is that $.get is queuing a request, but does not execute the request synchronously; it returns immediately. JavaScript is not multi-threaded!
You will have to execute console.log(icon) inside the callback function. At the point that line is being executed, the AJAX call has not completed yet.
The global icon variable will be set from the callback; your code is correct in that regard.