Web development
Conditions and Comparisons
Updated Oct 28, 2026
An if statement runs a block when its condition is true; else handles the alternative. Comparison operators such as === and > produce booleans. Use === for strict equality when you want to compare wit
What you’ll learn
Understand and practise conditions and comparisons.
Explanation
An if statement runs a block when its condition is true; else handles the alternative. Comparison operators such as === and > produce booleans. Use === for strict equality when you want to compare without automatic type conversion. Test both outcomes.
If ដំណើរការកូដពេលលក្ខខណ្ឌពិត ហើយ else សម្រាប់ករណីផ្សេង។ សញ្ញាប្រៀបធៀបដូចជា === និង > បង្កើតតម្លៃ true ឬ false។
Example
if (score >= 50) { console.log("Pass"); } else { console.log("Try again"); }
Practice
What is printed when score is 45?
Answer and explanation
Show answer / បង្ហាញចម្លើយ
Try again. The condition score >= 50 is false.
Quick recap
An if statement runs a block when its condition is true; else handles the alternative.