In JavaScript what does the "> -1" mean when used in an if statement? for example:
if(window.location.href.indexOf("about") > -1) {
//code
}
In JavaScript what does the "> -1" mean when used in an if statement? for example:
if(window.location.href.indexOf("about") > -1) {
//code
}
This is just doing a detection of the string about
in the URL. If about
is found in the URL, the block will execute.
The convention of indexOf
functions is to return -1
when the item isn't found.
indexOf returns -1 if the search fails and the index of the occurrence in the string if found...