I have an if-else condition in js as below and I am expecting else condition to execute for the below logic, because the destination ID is in else if, but it always goes into the if condition. tried with == and === too.
What am I missing? Note: The logic is to be supported in ie11
// destinationId is generated dynamically but i have assigned it to a variable for reference
Code 1
var fromId = "createNotification";
var destinationId ="detailedDescription";
if ((fromId == "createNotification") && (destinationId == "carNumber" || "setNumber")) {
//logic to execute
} else if ((fromId == "createNotification") && (destinationId == "faultRepBy" || "detailedDescription")) {
//logic to execute
}
code 2
if ((["createNotification"].indexOf(fromId) > -1) && (["carNumber" || "setNumber"].indexOf(destinationId) > -1)) {
//logic to execute
} else if ((["createNotification"].indexOf(fromId) > -1) && (["faultRepBy" || "detailedDescription"].indexOf(destinationId) > -1)) {
//logic to execute
}