document.ready() and variable scope

document.ready() and variable scope

Hi,
I don't yet understand some simple javascript / jquery basics:
 
  1. <head>
    <script language="javascript" type="text/javascript" src="jquery.js"></script>
    <script>
    var h = 11;
    $(document).ready(function()
    {
    h = $(window).height();
    alert(h);
    });
    </script>
    </head>
    <body>
    <script>
    alert(h);
    </script>













First I get the alert h=11 and only after that the value from $(window).height(), meaning I don't have the value of that height() available in the scripts in the body;
What am I doing wrong?
 
Similar, using javascript only:
 
  1. <head>
    <script>
    var h;
    function init()
    {
    h = 100;
    alert(h);
    }
    </script>
    </head>
    <body onload=init()>
    <script>
    alert(h);
    </script>












First I get the undefined, and then I get the 100.
Obviously there's something basic I don't yet understand.
 
Thanks.