The bitwise OR operator (`|`

) returns a `1`

in each bit position for which the corresponding bits of either or both operands are `1`

s.

a|b

The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32 bit integer:

Before: 11100110111110100000000000000110000000000001 After: 10100000000000000110000000000001

Each bit in the first operand is paired with the corresponding bit in the second operand: *first bit* to *first bit*, *second bit* to *second bit*, and so on.

The operator is applied to each pair of bits, and the result is constructed bitwise.

The truth table for the OR operation is:

a | b | a OR b |
---|---|---|

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 1 |

. 9 (base 10) = 00000000000000000000000000001001 (base 2) 14 (base 10) = 00000000000000000000000000001110 (base 2) -------------------------------- 14 | 9 (base 10) = 00000000000000000000000000001111 (base 2) = 15 (base 10)

Bitwise ORing any number

with `x``0`

yields

.`x`

// 9 (00000000000000000000000000001001) // 14 (00000000000000000000000000001110) 14 | 9; // 15 (00000000000000000000000000001111)

Desktop | ||||||
---|---|---|---|---|---|---|

Bitwise OR (`a | b` ) |
1 | 12 | 1 | 3 | 3 | 1 |

Mobile | ||||||
---|---|---|---|---|---|---|

Bitwise OR (`a | b` ) |
1 | 18 | 4 | 10.1 | 1 | 1.0 |

Server | |
---|---|

Bitwise OR (`a | b` ) |
0.1.100 |

© 2005–2018 Mozilla Developer Network and individual contributors.

Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.

https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR