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

184
Vistas
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 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