title: Javascript assigning the return value of a Callback function to global variable
body: <p>My question is about Javascript.
  I have a Callback function which receives a Position object on a successful callback.</p>
  
  <p>The problem is that when I try to set the properties of the Position object to a global variable at a successful callback it just does not let me do it and the global just remains undefined.</p>
  
  <p>As a workaround to that instead of directly setting the object properties to global variables i'm trying to return it through the callback function but I couldn't find a way to set the return value of the callback function to a global variable.</p>
  
  <p>Here's the simplified code.</p>
  
  <pre><code>var x;
  
  navigator.geolocation.getCurrentPosition(onSuccess, onError);
  
  //on Successful callback receives a Position Object
  function onSuccess(position) {  
    var coords = position.coords;  
      x=coords;       // Setting directly to an object does not work x still remains undefined after succesful callback               
  return coord; // Trying to set this to a global object 
  
  }
  
  // onError Callback receives a PositionError object
  //
  function onError(error) {
      alert('code: '    + error.code    + '\n' +
            'message: ' + error.message + '\n');
  }
  </code></pre>