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

90
Views
Declaraciones if anidadas con o condición

Tengo un código js que actualmente se parece a esto:

 var test //do some stuff with the var if (test === "A" || test === "B" || test === "C") { if (test === "A" || test === "B") { //do some small stuff } //do some more complex stuff }

¿Hay una mejor manera de escribir esto para evitar la condición duplicada? Parece básico, lo sé, pero no puedo identificarlo.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

podría asignar una variable para evitar tener que escribir la condición compleja varias veces:

 let a_or_b = test === 'A' || test === 'B'; if (a_or_b || test === 'C') { if (a_or_b) { // do some small stuff } // do more complex stuff }

o

 let a_or_b = false; if (test === 'A' || test === 'B') { // do some small stuff a_or_b = true; } if (a_or_b || test === 'C') { // do more complex stuff }
about 4 years ago · Santiago Gelvez Report

0

Mi sugerencia, solo configure la condición duplicada como una variable, espero que lo ayude

 var test; var isAOrB = (test === "A" || test === "B"); if (isAOrB || test === "C") { if (isAOrB) { //do some small stuff } //do some more complex stuff

}

about 4 years ago · Santiago Gelvez 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!