JavaScript: Checking a list for elements
<p>I'm currently learning JavaScript using Marijn Haverbekes excellent book "Eloquent JavaScript". Now there is this exercise where you have to write a recursive function that returns the nth element of a nested list. If there is no such element, the function is supposed to return <code>undefined</code>. The solution looks like this:</p>

<pre><code>function nth(list, n) {
  if (!list)
    return undefined;
  else if (n == 0)
    return list.value;
  else
    return nth(list.rest, n - 1);
}
</code></pre>

<p>So far, everything seems pretty clear to me. However, I don't really get what exactly <code>if (!list) {}</code> does. How exactly does this condition evaluate? Why is it true, if <code>list</code> has an element <code>n</code>?</p>

<p>The complete excercise can be found here:
<a href="http://eloquentjavascript.net/04_data.html#p_7AnSuS26HF" rel="nofollow">http://eloquentjavascript.net/04_data.html#p_7AnSuS26HF</a></p>