Skip to content

Boolean logic in programming languages: Python, JavaScript, SQL, Excel and more

Boolean logic in Python, JavaScript, SQL, Excel, Java, C, SMT-LIB and LaTeX: the operators, the precedence, the traps, and the same rule exported by the engine where it has an exporter.

The symbols page is the parser's own table: every spelling the engine accepts in each notation and every spelling it rejects with the repair it offers, from = and == to ^, &, ~ and juxtaposition. The language pages take one rule, the entry rule, and show how it reads in each language, what the precedence rules do to an unbracketed version, and which language-specific trap applies: truthiness in JavaScript and Python, three-valued NULL logic in SQL, bitwise versus logical operators in C and Java, text booleans in Excel.

For Python, PostgreSQL, SMT-LIB and LaTeX the snippet on the page was generated by the Tangibool exporter and is the code the product's own test suite executes; for the other languages the snippet was written and checked by hand.

If you came here from a search like “python boolean operators precedence”, the precedence page in the operators section gives the engine's precedence, and the Python page gives Python's, which differ in one important way: in Python, not a == b means not (a == b).

Questions

Why does SQL get its own pitfall?

SQL has three truth values: TRUE, FALSE and NULL. A rule that is a tautology in two-valued logic, such as a OR NOT a, is not always TRUE in SQL when a is NULL. The engine's SQL export documents a non-null input contract for exactly this reason.

Generated from the Tangibool engine, semantics tangibool-semantics/1, engine 1.0.0, build . Every table, map, simplification and verdict on these pages was computed by the Tangibool engine when the site was built, and every claim was re-checked by the same exact checker the app uses. Limits are stated where they apply. © 2026 Foreranger LTD.