A look at how bitwise operations work in JavaScript, what a binary system is, and how to convert numbers from decimal to binary and back again.

Bitwise operations aren’t very common in JavaScript, but sometimes they’re indispensable.

To understand how bitwise operations work in JavaScript, you need to first understand what a binary system is and how to convert numbers from decimal to binary and back again.

An introduction to the binary number system can be found here.

Bitwise operators in JavaScript are quite hard to understand if you apply them to decimal numbers.

I suggest starting with a piece of paper and a pencil and writing down all the numbers in binary.

The operators `&`

, `|`

and `^`

require two numbers to function properly. They compare the bits in these numbers one-by-one, applying the rules from the table above.

Let’s try them out. The binary representation of a decimal number is in the comment.

```
const x = 5; // 0101
const y = 6; // 0110
```

It’s easier if you write the binary numbers one under the other like this:

```
AND 0101 OR 0101 XOR 0101
0110 0110 0110
---- ---- ----
0100 0111 0011
```

Now, we can add `console.log`

and see if our calculations were right:

```
console.log(x & y); // 4
console.log(x || y); // 7
console.log(x ^ y); // 3
```

An important trick with XOR is that if you place the same number on both sides of it, you’ll always get zero.

```
console.log(x ^ x); // 0
console.log(y ^ y); // 0
```

On the contrary, if you replace `^`

with either `&`

or `|`

the number won’t change.

List of some useful JavaScript Frameworks and libraries for website, web apps, and mobile apps development, that developers should know about to make selection easier.

whatsapp web-w app web-webs whatsapp-web.whatsapp.com-wsp web-web.whatsapp.com qr-whats up online-whatsappwebsite

JavaScript Shopping Cart - javascript shopping cart tutorial for beginnersBuy me a coffee 🍺 https://www.paypal.com/paypalme/ziddahSource Code: https://bit....

### In this video I will tell you How to create a calculator using javascript very easily. <iframe width="560" height="315" src="https://www.youtube.com/embed/Q8JXnIR80kU" frameborder="0" allow="accelerometer; autoplay; clipboard-write;...

The essential JavaScript concepts that you should understand - For successful developing and to pass a work interview