title: Recursion in JavaScript With IF and WHILE
body: <p>I just come up with little strange behavior in Javascript Recursion. My code </p>
  
  <pre><code>var temp1 = function(maxLength,accNumber) {
  
      if(accNumber.length &lt; maxLength)
      {
          accNumber = '0'+accNumber; 
          temp1(maxLength,accNumber);
      }
      return accNumber;
  };
  console.log(temp1(5,"23")); 
  </code></pre>
  
  <p><strong>So Here I am expecting output as "00023" but its giving "023" which is not expected.</strong> </p>
  
  <p><strong>But same code with while loop I am getting expected output. I am not understanding why.</strong> </p>
  
  <pre><code>var temp1 = function(maxLength,accNumber) {
  
      while(accNumber.length &lt; maxLength)
      {
          accNumber = '0'+accNumber; 
          temp1(maxLength,accNumber);
      }
      return accNumber;
  };
  console.log(temp1(5,"23")); 
  </code></pre>
  
  <p>Which give me output "00023" as expected.</p>