I am building a BODMAS calculator using JavaScript, and working on some code to iterate through all the terms of the equation to find certain mathematical operators and numbers.
var AddPresent = EquationTerms.search(5);
console.log(AddPresent);
If number five is present in the string EquationTerms, it logs the index/position of the number in the string to the console of my browser. If it is not present, it logs -1. While this does not interfere with my program, I am curious: Why does it log -1, and not undefined, or null? I have searched online, but haven't found an answer which explains the reason. I would be grateful for one which explains this.