📊 JavaScript Operator Precedence
Last Updated: 12th October 2025
Operator precedence determines the order in which operations are performed in an expression.
Higher precedence operators are evaluated before lower precedence operators.
🗣 Hinglish Tip: Jaise maths me
*aur/pehle hota hai aur+aur-baad me, waise hi JS me operators ka order hota hai.
🧩 Precedence Table (Top to Bottom)
| Operator | Description | Example |
|---|---|---|
| () | Parentheses (grouping) | (2 + 3) * 4 → 20 |
| ++, -- (postfix) | Increment/Decrement after value | x++ |
| ++, -- (prefix), +, -, ~, ! | Unary operators | ++x, -5, !true |
| **, **= | Exponentiation | 2 ** 3 → 8 |
| *, /, % | Multiplication, Division, Modulus | 5 * 3 → 15 |
| +, - | Addition, Subtraction | 2 + 3 → 5 |
| <<, >>, >>> | Bitwise shifts | 5 >> 1 → 10 |
| <, <=, >, >=, in, instanceof | Comparison | 5 > 3 → true |
| ==, !=, ===, !== | Equality / Strict Equality | 5 === '5' → false |
| & | Bitwise AND | 5 & 1 → 1 |
| ^ | Bitwise XOR | 5 ^ 1 → 4 |
| | | Bitwise OR | 5 | 1 → 5 |
| && | Logical AND | true && false → false |
| || | Logical OR | true || false → true |
| ?? | Nullish Coalescing | null ?? 5 → 5 |
| ? : | Ternary Conditional | 5 > 3 ? "Yes" : "No" → Yes |
| =, +=, -=, *=, /=, %=, **=, &=, |=, ^=, <<=, >>=, >>>= | Assignment operators | x = 5 |
| , | Comma operator | (a=1, b=2) → 2 |
✏ Mini Examples
let a = 2 + 3 * 4; // Multiplication first → 2 + 12 = 14
let b = (2 + 3) * 4; // Parentheses first → 5 * 4 = 20
let c = (true && false) || true; // && first → false || true → true
let d = null ?? 10; // Nullish coalescing → 10
let e = 5 > 3 ? "Yes" : "No"; // Ternary → Yes
console.log(a, b, c, d, e); // Output: 14 20 true 10 Yes
🗣 Hinglish Tip: Jab confusion ho → use parentheses. Ye hamesha safe aur readable hota hai.
💡 Quick Practice
- Calculate 3 + 4 * 2 / (1 - 5) ** 2 step by step.
- Predict output of true || false && false.
- Check what null ?? "default" gives.
- Write a ternary for age >= 18 ? "Adult" : "Minor".