Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: userc865b
Added: Oct 24, 2018 1:30 PM
Views: 0
Tags: js
normal "||" is logical if (a || b) if a is true or b or both this one is XOR only one has to be true!!!!
  1. //https://stackoverflow.com/questions/4540422/why-is-there-no-logical-xor-in-javascript
  2.  
  3. var state1 = false,
  4.     state2 = true;
  5.    
  6. var A = state1 ^ state2;     // will become 1
  7. var B = !!(state1 ^ state2); // will become true
  8. console.log(A);
  9. console.log(B);