var not receiving correct value inside a function - Javascript : <p>I have this function called <strong>getQuotes()</strong>, and a <strong>console.log()</strong> at the end of it that shows the correct value of <strong>currentQuote</strong>.</p>

<pre><code>function getQuote() {
      $.ajax({
            headers: {
              "X-Mashape-Key": "xxx",
              Accept: "application/json",
              "Content-Type": "application/x-www-form-urlencoded"
            },
            url: 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies',
            success: function(response) {
                  var r = JSON.parse(response);      
                  currentQuote = r.quote;
                  currentAuthor = r.author; 
                  console.log(currentQuote);             
            }
      });
};
</code></pre>

<p>The point is: when I call <strong>getFunction()</strong> (like code below), then show a <strong>console.log</strong> of my variable <strong>currentQuote</strong>, it is not receiving the correct value, it still an empty string as declarated. What am I doing wrong ? </p>

<pre><code>$(document).ready(function() {  
    var currentQuote='';
    var currentAuthor='';             
    getQuote();  
    console.log(currentQuote);        
});
</code></pre>
