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

128
Visualizações
why does nullish coalescing executing two parts?

I have a method:

const objT2 = {
  calcAge(year) {
    console.log(2022 - year);
  },
};

but when I use the nullish coalescing both parts is being executed.

objT2.calcAge(1990) ?? console.log(`method not found`);
//output => 32    method not found
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

first you are calling calcAge method with 1990. so by calling it, the method gets executed objT2.calcAge(1990). this calculated 2022 - 1990 which is 32 and then logs it to the console. then this method returns undefined which gets evaluated as the left hand operand of the ?? operator. As this operator sees the left hand side is returning a nullish value (null or undefined), it goes on to execute the right hand side which logs method not found as well.

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