Using an object to replace the switch statement
<p>I found the following exemple on the jqfundamentals site. It seems to me that the else statement is unnecessary/wrong. So what am I missing ?</p>

<pre><code>var stuffToDo = {
    'bar' : function() {
        alert('the value was bar -- yay!');
    },

    'baz' : function() {
        alert('boo baz :(');
    },

    'default' : function() {
        alert('everything else is just ok');
    }
};

if (stuffToDo[foo]) {
    stuffToDo[foo]();
} else {
    stuffToDo['default']();
}
</code></pre>
