TIL (Today I Learned) is my collection of short, lightly edited, technical daily learnings. 271 and counting.
JavaScript Bitwise AND
The JavaScript bitwise AND operator (&) can be used for some real-world tasks, like testing if a number is odd or even. Odd-even checking might normally be done with a modulo and the number 2. // Checking 1 > 1 % 2 === 0 ? "Even" : "Odd" 'Odd' // Checking 2 > 2 % 2 === 0 ? "Even" : "Odd" 'Even' The bitwise AND is an alternative. When used between two numbers, it returns a new number that has 1’s in each position where both numbers have a 1. ...