Spot the Assignment vs Comparison Bug
Find the Mistake Medium
Question
This if statement always runs, even when score is not 100. What is wrong?
Code
let score = 50;
if (score = 100) {
console.log("Perfect score!");
}
Hint
One = assigns. Two or three = compare.
Explanation
The single = is the assignment operator, not a comparison. score = 100 assigns 100 to score and evaluates to 100 (which is truthy), so the if block always runs. The fix is if (score === 100) to compare without coercion.
Related Resources
Related Lessons
- Conditions (if/else)
Learn how if/else conditions work.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.