+ 10
What's & and | in Javascript?
I came across something like below in Javascript. document.write(2 | 6 & 5); I know the logical && and || but that above I don't know.
2 Answers
+ 21
Bitwise "AND" (&) and "OR" (|) operator.
+ 5
| and & are "bitwise or" and "bitwise and" operator.
like 2|6 will be
(2=001)|(6=110) ->(111=7)
6&5 will be
(6=110)&(5=101)->(100=4)
and so on.
means they are bitwise logic operator, logical operation is applied to each bits.