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

183
Views
alternativas para múltiples condiciones if else para hacerlo en una sola línea - javascript

En una función, estoy comprobando un par de condiciones con varias condiciones si no. Quiero hacer con el uso del operador ternario para que sea de una sola línea. no puedo configurarlo como hacerlo

 if (!this.$route.params.prdKey) { this.prodData.prdKey = ''; } else { this.prodData.prdKey = this.$route.params.prdKey; } if (!this.$route.params.version) { this.prodData.version = 1; } else { this.prodData.version = this.$route.params.version; } this.pageMode = this.$route.params.pageMode; this.getProductDetailsList(); if (!this.isPrdAvailable) { this.getproductList(); } else { this.loadMoreproducts(); }

Cualquier otro enfoque también está bien para mí. Hay en otra parte donde estoy usando este tipo de verificación de condición if-else varias veces. Entonces, puedo eliminar esos también.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

|| se puede usar para alternar entre dos posibilidades: si el lado izquierdo es verdadero, se evaluará como tal, de lo contrario, se evaluará como el lado derecho.

 this.prodData.prdKey = this.$route.params.prdKey || ''; this.prodData.version = this.$route.params.version || 1;
about 4 years ago · Juan Pablo Isaza Report

0

Podrías usar dos expresiones ternarias aquí:

 this.prodData.prdKey = this.$route.params.prdKey ? this.$route.params.prdKey : ''; this.prodData.version = this.$route.params.version ? this.$route.params.version : 1;
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!