title: Scope within recursive function?
body: <p>Edited for clarity:</p>
  
  <p>The code aims to remember where it's been with the valid property and there are a finite number of possible paths. </p>
  
  <p>For example, in a 4x4 grid: start at (1,1), then can you go N, S, E, or W? N (which is (1,2)) is the new start. From (1,2): N? No. E? Yes. Start again at (2,2). Continue until all possible paths have been explored.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getTestSubjects(current){
   //returns an array unique to current
  }
  var successes = [];
  var currentPath = [];
  
  function nextStep(current){
   currentPath.push(current);
      current.valid = false;
   if (currentPath.length === desiredLength){
    successes.push(currentPath);
  
    //line X
    return
   }
   var testSubjects = getTestSubjects(current);
   for(i=0;i&lt;testSubjects.length;i++){
       if(testSubjects[i].valid === true){
             nextStep(testSubjects[i])
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My question pertains to the locality of variables in recursive functions.
  For every time nextStep() is called, is a unique local variable testSubjects created,
  or does the same variable (local to the first call of nextStep()) change what it holds?</p>
  
  <p>When the for loop reaches a point where testSubjects[i].valid === false, will it return to the previous call of nextStep and keep looping?</p>
  
  <p>Also, if at lineX, I write currentPath = [] to clear the path and continue searching for other successful paths, will it affect the currentPath already pushed to the successes array?</p>
  
  <p>I hope this makes sense. I'm still a baby programmer. Please ask if you need any clarification and thanks in advance!</p>