Though undefined in console, javascript variable within setInterval shows its value on alert box
<p>javascript snippet :</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(document).ready(function() {

    setInterval(function() {
        $.getJSON('notif.php', function(data) {
            my_var = '123';
        });
        alert("my var =" + my_var);
    }, 2000);

});    
&lt;/script&gt;
</code></pre>

<p>in chrome and FF console, my_var shows to be undefined, but its value is shown on the alertbox. if undefined , then how is its val</p>

<p>What is the explanation ?</p>
