Javascript : string contains - with brief explanation and example

How to check if a string is contained a specific word or in technical terms : another string or substring in Javascript ? For those who usually works with Java may expect something like:

str.contains("substring")

However, there's no such thing in Javascript. To check if a string is contained another string, we need to utilize indexOf method. This is the example how it works:

var str = "Javascript : string contains";
var is_contained = str.indexOf("script");
alert(is_contained);

If we run above codes, we will get an alert box with 4. You can see how it works at the following pictures (click it to make it larger):
This is the explanation how indexOf method works. That method will return the substring position inside the string. In our case, the position of "script" is at 4th character (the first one is marked as 0). Now, let's doing a little experiment by changing the codes above to this one :
var str = "Javascript : string contains";
var is_contained = str.indexOf("scripts");
alert(is_contained);

What happen if we run those modified codes ? We'll see an alert box with -1 inside it, as shown on the following images (click it to make it larger):

Conclusion
After seeing both of the images above, we can conclude that indexOf method will return  -1 if the substring given isn't contained on the string. Based on it, we can build a condition block such :
var str = "Javascript : string contains";
var is_contained = str.indexOf("scripts");
if(is_contained==-1){
 //do your stuff here if the string is not contained given substring
}