Scope of variables inside of javascript
<p>I have the following code sample that im trying to wrap my head around</p>

<pre><code>        $(document).ready(function () {

        test("load json", function () {

            length = 0; // length = 0

            $.getJSON("plugins/form.json", function (data) {
                length = data.fields.length; // length = 4
            });

            ok(length == 4, "length = " + length.toString()); // length = 0? wtf?
        });
    });
</code></pre>

<p>the 'length' variable does not persist when the $.getJSON runs.  I cant figure out if its because its asynchronous or because the variable is out of scope.</p>
