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.

  • Custom User Avatar

    Is this how str[0] works here? for example: abc

    "abc"
    (reverse(bc) + "a")
    (reverse(c) + "b") + "a")
    ("c" + "b" + "a")
    "cba"