Check if a string ends with the given target string

Explanation:

  • String.prototype.substring() method: returns a subset of a string between one index and another, or through the end of the string.

Since if indexEnd is omitted, substring() extracts characters to the end of the string.

Therefore, in this syntax, it returns between (str.length: 16 — target.length: 9) str[6] and end of str. //str = “westernaustralia”

Now, str.substring(str[6]) is equal to target string which is “australia”, so it returns true.