Possible Duplicate:
What does the ^ operator do?
>>> var foo = [1,2]
>>> var bar = [3,4]
>>> foo ^ bar
0
>>> foo ^ 3
3
>>> 1^3
2
What is the purpose of the operator: ^?
Edit 1: Can you explain why
>>> foo ^ bar
0
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the case of
1^3, the XOR operator does some binary stuff to get 2.JavaScript sees the array syntax
[x,y]asNaNwhen you start doing math-y things with it.NaNis interpreted as0when you do bitwise operations on it, so thefooandbarmath starts to make sense taking that into account:Which seems to hold true.
[1,2]^7 = 7,[1,2,3]^9 = 9, etc.