title: Undefined Variable right after assignment
body: <p>I' trying to iterate through an array assigned to a variable, but the IDE I am using tells me that the variable is undefined. I tried to trouble shoot the problem by using <code>console.log(variable_name.length)</code> and it successfully returns the length of the array, but it still tells me that the variable is undefined when trying to iterate through it.</p>
  
  <pre><code>function availableActions(state, reward_matrix) {
    var current_state_row = reward_matrix[state];
    console.log(current_state_row.length);
  
    let av_act = [];
  
    for (var i = 0; i &lt; current_state_row.length; i++) {
      if (current_state_row[i] != 0) {
        av_act.push(i);
      }
    }
  
    return av_act;
  }
  </code></pre>
  
  <p>After trying to run the script I get the following error:</p>
  
  <pre><code>TypeError: current_state_row is Undefined
  </code></pre>
  
  <p>This example program returns <code>undefined</code> among a series of arrays. I believe that is what is causing the error.</p>
  
  <p>MRE</p>
  
  <pre><code>function getRand(min, max) {
    let rand = Math.random();
    let number = rand * (max - min) + min;
    number = Math.round(number);
    return number;
  }
  
  let total = 0;
  
  let grid = new Array(100)
  for(var i = 0; i &lt;100; i++){
    grid[i] = []
    for(var j = 0; j &lt; 10; j++){
      grid[i].push(0)
      total++
    }
  }
  
  for (var i = 0; i &lt; 200; i++) {
    let x = getRand(0, grid.length);
    console.log(grid[x]);
  }
  </code></pre>