Javascript - Object loses it's value on function exit
<p>I've got this strange problem. In my code, I've a variable named "val1" which gets a value after a jQuery calling, but after existing the jQuery function it loses it's value.</p>

<p>Here's the code:</p>

<pre><code>var val1;
$.getJSON('some address', null, function (result) {
    val1 = result.names[0].name;
    alert(val1); //first alert
});
alert(val1); // second alert
</code></pre>

<p>On first alert, I get the needed value, but on the second Alert - I get "undefined".</p>

<p>Why?!</p>

<p>Thanks!</p>
