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

175
Visualizações
Javascript Bitwise Operator not behaving correctly

Looking at the following Switch statement, if my value is 3 (I have made sure the type of value is a number by using parseInt(value, 10) so that's not the problem - also console.log(typeof value) would result in 'number') the 'name' variable should be set to 'three'. it's not the case though, and the switch statement directly goes to default. to make sure that the logic is correct, I changed the value to '1' and the 'name' variable got set to 'one'. why doesn't this work for value '3'? It's blown my mind!

               switch (value) {
                 case 0:
                    name = "zero";
                    break;
                 case (value & 1 == 1):
                    name = "one";
                    break;
                 case (value & 2 == 2):
                    name = "two";
                    break;
                 case (value & 3 == 3):
                    name = "three";
                    break;
                 default:
                 break;
               }

any ideas?

about 4 years ago · Juan Pablo Isaza
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