variable scope clarification
===

I have a snippet of javascript code, that I have found in the "**Secrets of the JavaScript Ninja**" (a John Resig book). I have a problem to understand the behaviour of a variable. 
The following is the code (simplified with respect to the original one):


    (function() {
        var results;
        this.assert = function assert() {
            var li = document.createElement("li");
            results.appendChild(li);
            return li;
        };
        this.test = function test(name, fn) {
            results = document.getElementById("results");
            results = assert().appendChild(document.createElement("ul"));
            fn();
        };
    })();
    window.onload = function() {
        test("A test.", function() {
            assert();
            assert();
        });
    };


My problem is the **results** variable. When you enter the "test" function, the results variable will take the value **"ul#results"** first and then the value **"ul"**, as a result of the **appendChild** function. But when you enter the **"fn()"** function the value of "results" is still "ul#results". Why? I have some difficult to understand the scope of this variable. 

Can someone help me to understand this topic?

Thank you very much.