JavaScript Operators Cheat Sheet
A JavaScript operators cheat sheet with precedence, arithmetic, comparison, logical, nullish, bitwise and assignment operators, with exact Node.js 24 output.

JavaScript has about sixty operators, and only a dozen of them cause real confusion: the ones that convert types, the ones that short-circuit and the ones whose precedence is not what a reader assumes. This cheat sheet lists every operator family with its behavior on Node.js 24 and shows the exact output for the cases that surprise people, such as ** being right-associative, % taking the sign of the left operand, ?? differing from || for 0 and the empty string, and >>> turning a negative number into a large positive one. A short precedence table ends the sheet. If you remember one rule, use parentheses wherever you would otherwise have to look up the order.
Arithmetic
| Operator | Meaning | Note |
|---|---|---|
+ - * / | add, subtract, multiply, divide | + also concatenates strings |
% | remainder | takes the sign of the left operand |
** | exponent | right-associative |
++ -- | increment, decrement | prefix returns the new value, postfix the old |
+x -x | unary plus and minus | +x converts to a number |
console.log(7 % 3, -7 % 3, 7 % -3, 5.5 % 2);
console.log(2 ** 3 ** 2, (2 ** 3) ** 2, (-2) ** 2);
console.log(7 / 2, Math.trunc(7 / 2), 7 / 0, -7 / 0, 0 / 0);
let n = 5;
console.log(n++, n, ++n, n);
console.log(+"42", +"", +"abc", +true, +null, +undefined);1 -1 1 1.5
512 64 4
3.5 3 Infinity -Infinity NaN
5 6 7 7
42 0 NaN 1 0 NaN% is a remainder, not a mathematical modulo, so -7 % 3 is -1. To get a result that is never negative, use ((a % n) + n) % n. 2 ** 3 ** 2 means 2 ** (3 ** 2), which is 512. Writing -2 ** 2 without parentheses is a SyntaxError, because the language refuses to guess whether you mean the negative of a square or the square of a negative. Division by zero gives Infinity and does not throw, except for BigInt.
Comparison and equality
| Operator | Meaning |
|---|---|
=== !== | strict equality, no type conversion |
== != | loose equality, with conversion |
< > <= >= | relational, numeric or alphabetical |
Object.is(a, b) | like ===, but NaN equals NaN and 0 differs from -0 |
console.log(1 === "1", 1 == "1", null == undefined, null === undefined);
console.log("10" < "9", 10 < "9", "a" < "b", null >= 0, undefined >= 0);
console.log(NaN === NaN, Object.is(NaN, NaN), 0 === -0, Object.is(0, -0));
console.log([] == [], {} == {}, "b" > "a" > "Z");false true true false
true false true true false
false true true false
false false falseTwo strings compare by code units, so "10" < "9" is true, while a number and a string convert the string to a number. Objects compare by identity, so two separate empty arrays are never equal. The last chain is ("b" > "a") > "Z", which is true > "Z", then 1 > NaN, then false. Use === as the default, and == null only when you mean "null or undefined".
Logical and nullish
&&returns the first falsy operand, or the last operandthe double vertical bar
||returns the first truthy operand, or the last operand??returns the right side only if the left isnullorundefined!is logical not, and!!xconverts to a boolean?:is the conditional,cond ? a : b
console.log(0 || "default", 0 ?? "default", "" || "x", "" ?? "x");
console.log(null ?? undefined ?? "last", 1 && 2 && 3, 1 && 0 && 3);
console.log(!!"text", !!"", !!0, !![], !!{}, !!NaN);
const settings = { retries: 0, name: "" };
console.log(settings.retries || 3, settings.retries ?? 3, settings.name || "anon");default 0 x
last 3 0
true false false true true false
3 0 anon|| treats every falsy value as missing: 0, "", false, NaN, null and undefined. ?? treats only null and undefined as missing, so a legitimate zero or an empty string survives. For defaults of numbers and strings, ?? is almost always what you meant. Mixing ?? with || or && without parentheses is a SyntaxError. The empty string in the first output line prints as nothing, which is why the line ends with a space.
Assignment
=assigns+=,-=,*=,/=,%=and**=combine an operation with assignment, soa += bisa = a + b&&=assigns only if the left side is truthy||=assigns only if the left side is falsy, and??=assigns only if it isnullorundefined[a, b] = [b, a]is destructuring assignment, and swaps two variables
const options = { timeout: 0, retries: undefined };
options.timeout ||= 30;
options.retries ??= 3;
options.verbose &&= true;
console.log(options);
let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a, b);{ timeout: 30, retries: 3 }
2 1The logical assignment operators assign only when needed, so the right side is not even evaluated otherwise. They came in ES2021 and work in Node.js 15 and later. Note that timeout ||= 30 replaced a deliberate 0, which is the same trap as with ||, and timeout ??= 30 would have kept it.
Bitwise
&,^and~are bitwise and, xor and not on 32-bit integers, and the vertical bar|is bitwise or<<shifts left, and>>shifts right keeping the sign>>>shifts right filling with zeros
console.log(5 & 3, 5 | 3, 5 ^ 3, ~5, 1 << 4, -16 >> 2, -1 >>> 0);
console.log(2 ** 32 | 0, 2 ** 31 | 0, 3.9 | 0, -3.9 | 0, ~~7.2);1 7 6 -6 16 -4 4294967295
0 -2147483648 3 -3 7Bitwise operators convert their operands to 32-bit signed integers first, which makes x | 0 and ~~x a truncation trick that is wrong for numbers beyond 2 to the 31st power. Use Math.trunc for clarity. Flags and masks are the real use: permissions & WRITE tests a bit, and permissions |= WRITE sets it. BigInt supports the same operators except >>>.
Type, membership and structure
| Operator | Meaning |
|---|---|
typeof x | a type name as a string |
x instanceof C | whether C.prototype is in the prototype chain of x |
"key" in obj | whether the property exists, including inherited ones |
delete obj.key | removes an own property |
void expr | evaluates and returns undefined |
a, b | comma: evaluates both, returns the last |
...x | spread in calls, arrays and objects, and rest in patterns |
?. | optional chaining, obj?.a, obj?.[k], fn?.() |
new C() | construct |
await x | wait for a promise inside an async function or a module |
class A {}
const obj = { a: 1, nested: { b: 2 } };
console.log(typeof 1n, typeof Symbol(), typeof function () {}, typeof class {});
console.log(new A() instanceof A, "a" in obj, "toString" in obj, Object.hasOwn(obj, "toString"));
console.log(obj.missing?.deep, obj.nested?.b, obj.fn?.(), void 0);
console.log(delete obj.a, obj);
console.log(Math.max(...[1, 5, 3]), { ...obj, extra: true });bigint symbol function function
true true true false
undefined 2 undefined undefined
true { nested: { b: 2 } }
5 { nested: { b: 2 }, extra: true }in also reports inherited properties, such as toString, so use Object.hasOwn for own properties. Optional chaining stops at the first null or undefined and returns undefined, and it works for property access, bracket access and function calls. typeof never throws, even for names that were not declared.
Precedence, highest first
| Level | Operators |
|---|---|
| 1 | grouping ( ) |
| 2 | member access . ?. [ ], call ( ), new with arguments |
| 3 | postfix ++ -- |
| 4 | prefix ++ --, unary + - ! ~, typeof, void, delete, await |
| 5 | **, right-associative |
| 6 | * / % |
| 7 | + - |
| 8 | << >> >>> |
| 9 | < > <= >= in instanceof |
| 10 | == != === !== |
| 11 | bitwise and, then bitwise xor, then bitwise or |
| 12 | logical and, then logical or and ?? |
| 13 | ?: and assignment, right-associative |
| 14 | ... and comma |
console.log(1 + 2 * 3, (1 + 2) * 3, 2 + 3 + "4", "4" + 2 + 3);
console.log(true || false && false, (true || false) && false);
console.log(1 < 2 < 3, 3 > 2 > 1);7 9 54 423
true false
true false3 > 2 > 1 is (3 > 2) > 1, which is true > 1, or 1 > 1, which is false. Comparisons do not chain the way they do in mathematics. When the order is not obvious on first read, add parentheses: it costs nothing and removes the need to consult a table.
Habits that avoid operator bugs
A few habits cover most of the trouble. Use === and !==, and treat any == in a review as a question. Use ?? for defaults, and write || only when you want every falsy value replaced. Put parentheses around mixed arithmetic and logical expressions, even when the precedence is correct, because the next reader may not remember it. Do not use the increment operators inside larger expressions, since a[i++] = b[i] depends on the order of evaluation that few people can recite. Convert types on purpose, with Number(), String() and Boolean(), and not through +x, x + "" and !!x, unless the short form is the established idiom in your codebase. And let a linter enforce the rules that are easy to forget, such as eqeqeq, no-implicit-coercion, no-mixed-operators and no-extra-boolean-cast.
Where this sheet stops
Operators on BigInt, Symbol and Proxy objects have their own rules, and the with statement and the old arguments quirks are best avoided. TypeScript adds as, satisfies and the non-null ! operators, which do not exist at runtime. And some operators have a proposal in progress, such as the pipeline operator, that is not part of the language yet.


