1
2 | 3 //Output is 3
7 | 9 //Output is 15

I tried 2 | 3 in the console and I got an output of 3. When I did 7 | 9, the output is 15. How does it work?

John Kugelman
  • 307,513
  • 65
  • 473
  • 519
Jibin John
  • 63
  • 2
  • 4
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR – DigitalDrifter Nov 14 '20 at 05:05
  • 2
    Does this answer your question? [What are bitwise operators?](https://stackoverflow.com/questions/276706/what-are-bitwise-operators), [What does this symbol mean in JavaScript?](https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript) – John Kugelman Nov 14 '20 at 05:06
  • 2
    See also: [Where would I use a bitwise operator in JavaScript?](https://stackoverflow.com/questions/654057/where-would-i-use-a-bitwise-operator-in-javascript) – John Kugelman Nov 14 '20 at 05:07

1 Answers1

2

It is the OR operator used for Bitwise Operations.

Example :

5 | 1

It will be the same as 0101 | 0001

Result: 0101 = 5

Reference.

yudhiesh
  • 3,560
  • 3
  • 7
  • 24
Harshana Serasinghe
  • 3,864
  • 1
  • 8
  • 17