Ad
  • Default User Avatar

    Yes. Javascript allows you to treat strings as character arrays, so str[0] refers to the first character of str.

    The only difference between accessing it like an array and using charAt (or any of the other string methods... slice, substr, or substring) is that if the index refers to a position outside the string's length, str[i] will result in the value undefined, while those other methods would return an empty string instead.