title: Recursion and returning values in javascript
body: <p>I've recently been practicing writing recursive functions in JavaScript, and I've been running into a problem consistently when it comes to return values, which is that they ALWAYS seem to be undefined when returned from inside a conditional block.</p>
  
  <p>Here is an example on jsFiddle</p>
  
  <p><a href="https://jsfiddle.net/g0dm68nm/" rel="nofollow noreferrer">https://jsfiddle.net/g0dm68nm/</a></p>
  
  <p>This is a simple binary sort implemented recursively. At this block of code</p>
  
  <pre><code>if (array[guess] === targetValue){
      console.log("equal");
      return(guess);
  }
  </code></pre>
  
  <p>I see in my console "equal", which would never happen unless</p>
  
  <pre><code>    A) The variable guess is defined
      B) The item located at the index of that array equals the target search value
  </code></pre>
  
  <p>So I know that guess is absolutely defined or else my function would never evaluate the console.log statement, but the value returned is always undefined.</p>
  
  <p>What am I missing? What is it that I am not understanding about recursion? This is the third function in the last 2 weeks I've written that behaves in the same way and I can't find any sort of answer anywhere online.</p>