Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptOR(|) Bitwise Operator in JavaScript

OR(|) Bitwise Operator in JavaScript

JavaScript Bitwise OR(|) Operator is used to compare two operands by performing OR operation on individual bits of the operands and returns true even if one of the compared bits is 1. The OR Operator has vast applications and the most used one is combining bit values. The operation is represented by the “|” symbol.

Let’s look at the truth table below to better understand the output of the OR operation between two bits.

A B OUTPUT ( A | B )
0 0 0
0 1 1
1 0 1
1 1 1

Syntax: 

a | b

Example 1: In this example, we will understand the basics of OR operation.

Javascript




let a=3;
let b=5;
console.log(a|b);


Output: 5 is represented as 101 and 3 is represented as 011. When the OR operation is performed 111 is returned which after conversion to decimal returns 7.

7

Example 2: In this example, we will use bitwise OR operation two combine bit values of both numbers.

Javascript




let a=24;
let b=45;
console.log(a|b);


Output: 24 is represented as 11000 and 45 is represented as 101101. When the OR operation is performed 111101 is returned which contains all the bits of both numbers and returns 61 as decimal output.

61

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

We have a complete list of JavaScript Bitwise Operators, to check those please go through, the JavaScript Bitwise Operators article

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments