var JOURNAL = [
{"events":["carrot","exercise","weekend"],"squirrel":false},
{"events":["bread","pudding","brushed teeth","weekend","touched tree"],"squirrel":false}]
function hasEvent(event, entry) {
var x = entry.events.indexOf(event)
console.log(x)
//-1
return x != -1;
}
hasEvent('pizza', JOURNAL[0])
For example: There is no 'pizza' in JOURNAL[0], so it returns -1 which causes x to return false.
I understand that if it doesn't found the event, it returns -1!
My question is why does it return -1? Is there any reason behind it?
Many Thanks
Edit: Is asking this sort of question bad? That's why i got downvoted? Sorry!