Programming Questions

  • Newest
  • Popular Tags
  • Ask A Question
  • Undefined JavaScript error
    var broked = broken[i].charAt(0).toUpperCase() + broken[i].substring(1);
    
    Why would this result in an error telling me that broken is undefined? It works fine when I don't use i within a for loop as the index.
    weweboom posted this question on 3/25/14 | javascript
    Answers
  • +
  • 1
  • -
  • You need to include more code here. The context is important. There is no way for us to tell if you're doing something silly with "broken" before this line or not.
  • +
  • 0
  • -
  • HI weweboom, I assume "broken" to be an array you loop over in a for/while loop? Then you 're probably trying to access an item of broken via the "i"-index and the value of "i" is greater than the length of broken. Example: var broken = ["a","b","c"]; broken.length // 3 broken[0] = =="a"; broken[1] = =="b"; broken[2] = =="c"; broken[3] === undefined I suspect your for loop to be something like this: for(var i = 0; i <= broken.length;i++) { }
  • +
  • 0
  • -
  • Do you have out of boundary error? I mean if the value of the index is too big or small, you could get undefined value.
  • +
  • 0
  • -
  • I believe this is coderbyte editor specific. Even I faced the same challenge.
    Log in to write an answer.