title: Javascript Uncaught TypeError: Cannot read property '0' of undefined
body: <p>I know there's plenty of questions related to this error and I've checked most of them and none help me solve my issue. (Which seems so easy to debug...)</p>
  
  <p>I have an array (which is empty aat first):</p>
  
  <pre><code>var words = [];
  </code></pre>
  
  <p>And my function hasLetter, checks if we find a letter (object) in the array (that I call here: d) words.</p>
  
  <pre><code>function hasLetter(letter,d){
  
  // if words[0] not null should return object of letter "a", here we getting
  // the index of the letter (since ascii of "a" is 97, I substract 97)
  var ascii = letter.charCodeAt(0)-97;
  
  //Trying to not get an error with this but still creates an err
  if(typeof d[ascii ] !== "undefined" &amp;&amp; d[ascii ] !== null &amp;&amp; d[ascii ].length &gt; 0){
      if(d[ascii].letter == letter){
          return true;
      }
  }
  return false; }
  </code></pre>
  
  <p>and I have a function called addLetter which checks if hasLetter returns true/false and then creates or not accordingly a new node.</p>
  
  <pre><code>function addLetter(letter,d){
  var ascii = letter.charCodeAt(0)-97;
  if(!hasLetter(letter,d)){
      document.write("This letter" + letter + " hasn't been found in words.");
      d[ascii] = new Node(letter);
  }
      document.write("This letter " + letter + " already exists in words.");
      document.write(d[ascii].letter);
  </code></pre>
  
  <p>}</p>
  
  <p>and if I test:</p>
  
  <pre><code>addLetter("a",words);
  </code></pre>
  
  <p>it returns:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property '0' of undefined
  </code></pre>
  
  <p>I don't know what to do to say "if it's undefined then don't look into it or something along those lines...</p>
  
  <p>Thanks</p>