title: Get a variable value outside from within a function defined by "var somthing ="
body: <p>This is a function used in jQuery UI widgets and plugins  - </p>
  
  <pre><code>var select = function( event, ui ) {
          var somevariable = 4;
      }
  </code></pre>
  
  <p>How can I get the value of <code>var somevariable =</code> outside this function?</p>
  
  <p>Using it as a global variable doesn't work:</p>
  
  <pre><code>var somevariable;
  var select = function( event, ui ) {
          var somevariable = 4;
      }
  </code></pre>
  
  <p>In this code <code>var somevariable</code> doesn't get the value '4' when it is placed before or after <code>var select =</code></p>
  
  <p><strong>EDIT:</strong> To make it more detailed, I want to use this variable in another function like in the following jQuery UI plugin:</p>
  
  <pre><code>  $( "#id" ).autocomplete({
      minLength: 0,
      source: function( request, response ) {
  
          if (somevariable == 5)
          {
          //do something
          }
  
      },
      open: function( event, ui ) {
  
      somevariable = 5;
  
      }
  });
  </code></pre>
  
  <p>In this case when the <code>open:</code> event is triggered, the value does not get retrieved by <code>source:</code></p>