Is it better to return `undefined` or `null` from a javascript function?
<p>I have a function which I have written which basically looks like this:</p>

<pre><code>function getNextCard(searchTerms) {
  // Setup Some Variables

  // Do a bunch of logic to pick the next card based on termed passed through what I'll call here as 'searchTerms' all of this logic is omitted because it's not important for my question.
  // ...

  // If we find a next card to give, than give it
  if (nextCardFound)
    return nextCardFound;

  // Otherwise - I'm returning undefined
  return undefined;
}
</code></pre>

<p><strong>Question: Would it be better to return "null" here?</strong></p>

<p>I can pass whatever I want back - obviously...  I just wasn't sure what is the best thing to use.</p>

<p>The code that calls this function knows how to deal with undefined (it actually won't ever really happen unless something goes horribly wrong)</p>

<p>The reason I'm asking this question is that I heard somewhere something that sounded like "Don't assign undefined to variables" or something - that it will make it harder to debug.  So, the fact that I can see that <code>null</code> gets passed back tells me that the return is working - but basically function similar to <code>undefined</code>.</p>

<hr>

<h2>Documentation:</h2>

<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined" rel="noreferrer">Mozilla Docs</a> Didn't answer my question... google didn't either :\</p>

<p><a href="https://stackoverflow.com/questions/6604749/what-reason-is-there-to-use-null-instead-of-undefined-in-javascript">This SO Question</a> - was way too broad for what I'm trying to figure out here.</p>