A javascript variable defined outside a function is 'undefined' within the function
<p>Why is <code>MM_SYSTEM_RESTART_SECONDS</code>  <code>undefined</code> in the following snippet?</p>

<p>If <code>var MM_SYSTEM_RESTART_SECONDS  = 40;</code> is put inside the function, then <code>MM_SYSTEM_RESTART_SECONDS</code> is <code>40</code>, but if outside the function,
then <code>MM_SYSTEM_RESTART_SECONDS</code>  is always <code>undefined</code>.</p>

<pre><code>var MM_SYSTEM_RESTART_SECONDS = 40;


function wait_until_MM_restarts()
{
    restart_timeout_start_seconds = get_cookie( "restart_timeout_start_seconds" )
    elapsed_restart_seconds =  elapsed_seconds( restart_timeout_start_seconds )
    append_debug_message( elapsed_restart_seconds + "/" +   MM_SYSTEM_RESTART_SECONDS )
    if( elapsed_restart_seconds &gt; MM_SYSTEM_RESTART_SECONDS )
</code></pre>
