The code sample above shows an example of a regex literal. The constant
literalRegex is used to represent a regex expression that matches any string that ends with the letter 'y'. Therefore, the first
console.log() statement prints the last index of the string while the second statement prints -1 (meaning it does not exist). The second example of a regex is shown using a function constructor. The function constructor uses the keyword
new to create a regular expression. The new regex matches any string that starts with the letter 'T'. The two
console.log() statements that follow simply check if this condition is met and returns the index of the string (or -1).