LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 18

Bitwise AND, OR, XOR and NOT Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 18 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links