title: Cannot read property 'length' of undefined in nodejs
body: <p>I'm executing the following code in node js.</p>
  
  <p>I've a 2d array called graph declared at the top. If I access the property <code>graph[0].length</code> in <code>main()</code> function and also in <code>traverseGraph</code> function it successfully shows the value as 2. But, if I pass 0 as a value to <code>st</code> argument of <code>traverseGraph</code> function and then try to access <code>graph[st].length</code>, I get:</p>
  
  <blockquote>
    <p>Cannot read property 'length' of undefined error.</p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var graph = [[1,2], [2,3]];
  
  main();
  function traverseGraph(st)
  {
      console.log(graph[0].length);//successfully works
     while(graph[st].length)//fails
      {
          for(var array_el=0; array_el&lt;graph[st].length; array_el++)
          {
              if(graph[st][array_el]){
                  var next = graph[st][array_el];
                  return traverseGraph(next);
              }
          }
      }
      
      return next;
  }
  function main(){   
      console.log(graph[0].length); //successfully works
      traverseGraph(0);    
  }</code></pre>
  </div>
  </div>
  </p>