Javascript - Scope of variables within and outside functions : <p>I have an ajax request where i have a variable that i need to get outside the function. For some reason i am not able to get the values outside the function. For simplicity i am changing my function.</p>

<pre><code>        var myEvents = "hi";
        $.ajax({
            url: 'http://mywebsite.com/events',
            type: "post",
            success: function (response) {
                myEvents = 'hello';
            }
        });

        alert(myEvents); // shows "hi" but i want it to show "hello" 
</code></pre>
