| bitwise OR , which means that all bits equal to 1 in any of the arguments will be equal to 1 as a result. A bitwise OR with 0 returns the given input, interpreted as an integer.
In your code, it is widely used to convert Math.random () a number to an integer. Bottom line:
Explanation: Takevar a = 5;
var b = 6;
a|b a|a a|0
101 101 101
110 101 000
------ ------ ------
111-->7 101-->5 101-->5
Run codeHide resultAmit source
share