Challenge - 5 Problems
Operator Precedence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Remember that exponentiation (**) has higher precedence than multiplication and division, which have higher precedence than addition.
✗ Incorrect
The expression evaluates as 3 + (4 * 2) / ((1 - 5) ** 2) = 3 + 8 / 16 = 3 + 0.5 = 3.5.
❓ Predict Output
intermediate2:00remaining
What is the output of this logical and arithmetic expression?
What will the following code output?
Javascript
console.log(true || false && false);
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than ||.
✗ Incorrect
&& is evaluated first: false && false is false, then true || false is true.
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
Assignment operators are right-associative and have lower precedence than multiplication.
✗ Incorrect
b *= c means b = b * c = 2 * 3 = 6; then a += b means a = a + b = 1 + 6 = 7; console.log prints 7.
❓ Predict Output
advanced2:00remaining
What is the output of this expression with unary and binary operators?
What will the following code output?
Javascript
console.log(-3 ** 2);
Attempts:
2 left
💡 Hint
Unary minus has lower precedence than exponentiation in JavaScript, so -3 ** 2 is parsed as -(3 ** 2) = -9.
✗ Incorrect
In JavaScript, unary minus has lower precedence than exponentiation, so -3 ** 2 is parsed as -(3 ** 2) = -9.
❓ Predict Output
expert2: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));
Attempts:
2 left
💡 Hint
Bitwise AND (&) has higher precedence than logical AND (&&) and logical OR (||).
✗ Incorrect
5 & 3 = 1 (bitwise AND), 0 && 2 = 0 (logical AND), then 1 || 0 = 1 (logical OR).