## Clear as the sun explanation of De Morgan’s laws

Sometimes, novice developers struggle with basic logic expressions, especially De Morgan’s laws. To help with this, I have prepared a simple explanation.

The following examples were made using a small React app that I created for this article. You can choose to download and play with it or not 😀️. The following text doesn’t require the app installation.

## Step 1. Where are we from

Ok. Let start with the basics. How looks `a&&b`

result? I think everybody knows:

## Step 2. Let’s play with it

What if we negate

in this expression? Just imagine the column where **b**

was **b**

will changed to **true**

, and vice versa. The matrix will be flipped horizontally, like reflection in a mirror!**false**

And if we negate

, it will be flipped vertically:**a**

## Step 3. Try a little bit harder

What if we negate both

and **a**

the same time? Right! The matrix will be flipped in both directions – horizontally and vertically:**b**

## Step 4. The Final

Nice, and what if we negate the entire expression after negating

and **a**

? In that case the values in the matrix will change from **b**

to **true**

, and vice versa:**false**

But wait! It looks like matrix for** a||b**!

Actually that’s the **de Morgan’s Law**

`!(!a&&!b) === a||b or !a&&!b === !(a||b)`

I hope this article was helpful.

## Leave a Reply