Question 18
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log(5 & 3, 5 | 3, 5 ^ 3, ~5);
- A 1 7 6 -5
- B 8 7 2 5
- C 1 7 6 -6 Correct
- D true true false false
Correct Answer: Option C
5 = 101, 3 = 011: AND 001 = 1, OR 111 = 7, XOR 110 = 6. ~x equals -(x + 1), so ~5 is -6.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!