Predict Bitwise Operation
Predict Output Medium
Question
What does this code print?
Code
console.log(5 & 3);
console.log(5 | 3);
console.log(5 ^ 3);
Hint
Convert to binary: 5 = 101, 3 = 011.
Explanation
In binary: 5 = 101, 3 = 011. AND (&): 101 & 011 = 001 = 1. OR (|): 101 | 011 = 111 = 7. XOR (^): 101 ^ 011 = 110 = 6. Each result is printed on its own line. Bitwise operators work on 32-bit integers.
Related Resources
Related Lessons
- JavaScript Data Types
Learn about bitwise operators.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.