Bird
Raised Fist0
Javascriptprogramming~20 mins

Operator precedence in Javascript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Operator Precedence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this code with mixed operators?
Consider the following JavaScript code snippet. What will it print to the console?
Javascript
console.log(3 + 4 * 2 / (1 - 5) ** 2);
ASyntaxError
B1
C3.5
D3.75
Attempts:
2 left
💡 Hint
Remember that exponentiation (**) has higher precedence than multiplication and division, which have higher precedence than addition.
❓ Predict Output
intermediate
2:00remaining
What is the output of this logical and arithmetic expression?
What will the following code output?
Javascript
console.log(true || false && false);
Atrue
Bfalse
CSyntaxError
Dundefined
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than ||.
❓ Predict Output
advanced
2:00remaining
What is the output of this tricky assignment expression?
What will this code print?
Javascript
let a = 1; let b = 2; let c = 3; console.log(a += b *= c);
A7
B6
C9
DTypeError
Attempts:
2 left
💡 Hint
Assignment operators are right-associative and have lower precedence than multiplication.
❓ Predict Output
advanced
2:00remaining
What is the output of this expression with unary and binary operators?
What will the following code output?
Javascript
console.log(-3 ** 2);
A-6
B9
CSyntaxError
D-9
Attempts:
2 left
💡 Hint
Unary minus has lower precedence than exponentiation in JavaScript, so -3 ** 2 is parsed as -(3 ** 2) = -9.
❓ Predict Output
expert
2:00remaining
What is the output of this complex expression mixing bitwise and logical operators?
What will this code print?
Javascript
console.log((5 & 3) || (0 && 2));
A0
B1
C2
DSyntaxError
Attempts:
2 left
💡 Hint
Bitwise AND (&) has higher precedence than logical AND (&&) and logical OR (||).

Practice

(1/5)
1. Which operator has the highest precedence in the expression 3 + 4 * 2?
easy
A. Multiplication (*)
B. Addition (+)
C. Subtraction (-)
D. Division (/)

Solution

  1. Step 1: Recall operator precedence rules

    Multiplication and division have higher precedence than addition and subtraction.
  2. Step 2: Identify operators in the expression

    The expression has addition (+) and multiplication (*). Multiplication runs first.
  3. Final Answer:

    Multiplication (*) -> Option A
  4. Quick Check:

    Multiplication > Addition [OK]
Hint: Multiplication/division run before addition/subtraction [OK]
Common Mistakes:
  • Thinking addition runs before multiplication
  • Ignoring operator precedence
  • Assuming left-to-right always applies
2. Which of the following expressions is syntactically correct in JavaScript?
easy
A. 5 + (3 * 2)
B. 5 + * 3
C. 5 + 3 * )2(
D. 5 + 3 * 2)

Solution

  1. Step 1: Check each expression for syntax errors

    5 + * 3 has two operators in a row (+ *), which is invalid. 5 + 3 * )2( has misplaced parentheses. 5 + 3 * 2) has an unmatched closing parenthesis.
  2. Step 2: Confirm correct syntax

    5 + (3 * 2) uses parentheses correctly and has valid operators and operands.
  3. Final Answer:

    5 + (3 * 2) -> Option A
  4. Quick Check:

    Valid parentheses and operators [OK]
Hint: Check parentheses and operator placement carefully [OK]
Common Mistakes:
  • Misplacing parentheses
  • Using two operators together
  • Unmatched parentheses
3. What is the output of the following code?
console.log(10 - 2 * 3 + 4 / 2);
medium
A. 8
B. 12
C. 6
D. 10

Solution

  1. Step 1: Apply operator precedence

    Multiplication (*) and division (/) run before addition (+) and subtraction (-). Calculate 2 * 3 = 6 and 4 / 2 = 2 first.
  2. Step 2: Calculate remaining expression

    Expression becomes 10 - 6 + 2. Calculate left to right: 10 - 6 = 4, then 4 + 2 = 6.
  3. Final Answer:

    6 -> Option C
  4. Quick Check:

    10 - 6 + 2 = 6 [OK]
Hint: Do * and / before + and -, then left to right [OK]
Common Mistakes:
  • Adding before multiplying
  • Ignoring division precedence
  • Calculating right to left
4. Find the error in this expression:
let result = 5 + 3 * / 2;
medium
A. No error, expression is valid
B. Incorrect use of parentheses
C. Division operator should be replaced with subtraction
D. Missing operand between * and /

Solution

  1. Step 1: Analyze the operator sequence

    The expression has '* /' operators together without a number between them, which is invalid syntax.
  2. Step 2: Identify the syntax error

    Every operator needs operands on both sides. Here, the '*' operator is missing its right operand before the '/' operator.
  3. Final Answer:

    Missing operand between * and / -> Option D
  4. Quick Check:

    Operators need operands on both sides [OK]
Hint: Operators must have numbers on both sides [OK]
Common Mistakes:
  • Ignoring missing operand
  • Assuming expression is valid
  • Confusing operator roles
5. Given the expression let x = 4 + 3 * 2 ** 2 / (1 + 1);, what is the value of x?
hard
A. 13
B. 10
C. 11
D. 14

Solution

  1. Step 1: Evaluate parentheses and exponentiation first

    Parentheses: (1 + 1) = 2. Exponentiation: 2 ** 2 = 4.
  2. Step 2: Calculate multiplication and division left to right

    Expression becomes 4 + 3 * 4 / 2. Calculate 3 * 4 = 12, then 12 / 2 = 6.
  3. Step 3: Perform addition

    Finally, 4 + 6 = 10.
  4. Final Answer:

    10 -> Option B
  5. Quick Check:

    Parentheses & exponentiation first, then * /, then + [OK]
Hint: Do parentheses, then **, then * /, then + [OK]
Common Mistakes:
  • Ignoring exponentiation precedence
  • Doing addition before multiplication
  • Miscomputing parentheses
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard