Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
alternatives for multiple if else conditions to make it in single line - javascript

In one function, i am checking couple of condition with multiple if else condition. I want to do with using ternary operator to make it single line. I am not able to configure it how to do that

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();
        }

Any other approach is also ok for me. There are in other part where i am using this kind of if-else condition check multiple times. So, i can remove those as well.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

|| can be used to alternate between two possibilities - if the left-hand side is truthy, it'll evaluate to it, otherwise it'll evaluate to the right-hand side.

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

0

You could use two ternary expressions here:

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda