I'm working with JS, I was trying to implement an algorithm while I realize that I could use myVar & 1
to return 0 or 1 according to the parity of the number in myVar.
var a = 0 & 1;
var b = 1 & 1;
var c = 42 & 1;
var d = 65 & 1;
console.log(a); //display 0
console.log(b); //display 1
console.log(c); //display 0
console.log(d); //display 1
https://jsfiddle.net/bzjvpyjk/
I don't understand what's happening behind it. How does it work?
Is it clear or even useful to do it?