Review: Logic Operators (MDN).
In Boolean Algebra:
De Morgan’s laws are a pair of transformation rules:
,
and
In Plain English:
The statements “I don’t like chocolate or vanilla” and “I do not like chocolate and I do not like vanilla” express the second rule, above.
Your turn: Express the first rule in English.
In Javascript:
and
!(x || y) == (!x && !y)
Applications:
De Morgan’s Laws can be used to simplify logical expressions in computer programs:
- Inverting Logical Expressions with De Morgan’s Laws.
- 1-Armed Bandits and De Morgan’s Laws.
- Exercise: Roll a Natural Seven (3-4, 4-3)
True & False in JavaScript
To test the truth value of any expression e: !!e