Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda