How bitwise OR works

Suppose we want to take a bitwise OR of 5 and 12:

  1. Covert both numbers to binary; 5 is 0101 and 12 is 1100
  2. Bitwise OR performs an OR operation bit by bit, starting from the first bit: 5  |  12 0 || 1 = 1 1 || 1 = 1 0 || 0 = 0 1 || 0 = 1
  3. Thus, 5 | 12 = 1101 which is 13.

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.