Error related to undefined variable
<p>What's wrong with this code? I get:</p>

<p>TypeError: older is undefined<br>
(10 out of range 3)</p>

<p>but older is defined at the beginning: <code>var older = people[0]</code></p>

<pre><code>function person(name, age) {
    this.name=name;
    this.age=age
}

function foo() {
    var older10 = function(people) {
        var older = people[0];

        for (var index = 1; index &lt; 10; index++) {
            if (people[index].age &gt; older.age) {
                older = people[index]; // error here
            }
        }
        return older;
    };

    var array = [];
    array[1] = new person("Paul", 23);
    array[2] = new person("Jim", 24);
    array[3] = new person("Sam", 84);
    array[4] = new person("Rob", 54);
    array[8] = new person("Karl", 19);
    array[9] = new person("", 0);

    var older = older10(array);

    if (older.name === "Sam") {
        console.log("ok");
    }
}
</code></pre>
