1

When I open the Chrome console and write following i get wierd results.

5^5 gives 0 

5^6 gives 3

3^8 gives 11

Also, attached a screenshot here enter image description here Does anyone have any idea?

This question is pure out of curiosity!

Cute_Ninja
  • 4,742
  • 4
  • 39
  • 63
  • 5
    Bitwise exclusive-OR. [There is an online language specification that contains answers to all sorts of questions like this.](http://www.ecma-international.org/ecma-262/5.1/) It's also the same operator in many other C-like languages. – Pointy Aug 14 '14 at 21:12
  • 2
    The Google search term for this is "mdn JavaScript operators" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators – Jeremy J Starcher Aug 14 '14 at 21:14
  • Thank you @Pointy. :) You are right! It adds up now. If you move your comment to answer, i can accept it – Cute_Ninja Aug 14 '14 at 21:15
  • The bitwise XOR is actually most commonly used to flip booleans, at least that's what I use it mostly for, and also where I most commonly see it, something like `var k=true; k ^= true;` which could also be written as `var k=true; k = !k;` – adeneo Aug 14 '14 at 21:20
  • @adeneo You've never done low-level bit twiddling then ;) Being able to pack 32 boolean flags into a single variable is memory efficient. :) *Though I do that more in other languages, I have done it JS too.* – Jeremy J Starcher Aug 14 '14 at 21:24
  • @JeremyJStarcher - I have, but not very often, and I rarely need XOR, usually it's just shifting bits. However I often use the `var ^= true;` trick, and that's also where I most often see the XOR in other code. – adeneo Aug 14 '14 at 21:30

0 Answers0