Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
Here, the searchString parameter is the string that we want to search for in the given string, and the optional position parameter is the position in the string where we want to start the search.
Let’s take an example to understand this better:
const str = 'Hello, World!';
console.log(str.includes('Hello')); // true
console.log(str.includes('world')); // false
In the above example, we have defined a string ‘Hello, World!’ and used the includes() method to check whether the string ‘Hello’ is present in it or not. The first console.log() statement returns true because the string ‘Hello’ is present in the given string, whereas the second console.log() statement returns false because the string ‘world’ (with a lowercase ‘w’) is not present in the given string.