Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
If else condition not working for string comparision in JS

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

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change your condition as below:

if ((fromId == "createNotification") && (destinationId == "carNumber" || destinationId == "setNumber")) {
 console.log("in if")
} else if ((fromId == "createNotification") && (destinationId == "faultRepBy" || destinationId == "detailedDescription")) {
 console.log("in else if")
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!