Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!