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).
- Logic symbols: meanings, LaTeX, Unicode and how to type them
Logic symbols and what they mean: ¬ not, ∧ and, ∨ or, → if … then, ↔ if and only if, and the quantifier and proof symbols ∀, ∃, ⊢, ⊨ and ∴. - Boolean logic in Python: and, or, not, precedence and common mistakes
Python spells the three basic operators as words, and, or and not, ranks them in that order below the comparison operators, and returns an operand rather than a plain Boolean from and and or. - Boolean logic in JavaScript: &&, ||, !, truthiness and precedence
JavaScript writes the operators as !, && and ||, ranks them in that order, and lets any value stand in for a Boolean through truthiness. - Boolean logic in SQL: AND, OR, NOT and the NULL three-valued trap
SQL has AND, OR and NOT with the usual precedence, and a third truth value, NULL, that silently changes what a rule does to rows with missing data. - Boolean logic in Excel: AND(), OR(), NOT(), XOR() and IF
Excel writes Boolean logic as functions: AND(), OR(), NOT() and XOR() take any number of arguments, and IF() turns the result into a value. - Boolean logic in Java: &&, ||, ! vs &, | and ^
Java has two sets of operators on boolean: &&, || and ! short-circuit, while &, | and ^ evaluate both sides and are also the bitwise operators on integers. - Boolean logic in C: logical vs bitwise operators
C has logical operators that produce 0 or 1 and bitwise operators that work on every bit, with similar spellings and different precedence. - Boolean logic in SMT-LIB: declare-const, assert and check-sat with Z3
SMT-LIB is the input language of solvers such as Z3: you declare Boolean constants, assert formulas in prefix notation and ask check-sat. - Boolean logic in LaTeX: \land, \lor, \lnot and truth tables
LaTeX typesets logic with macros: \land, \lor and \lnot for the connectives, \oplus for exclusive or, \rightarrow and \leftrightarrow for the arrows, and an array or tabular for a truth table.
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.