Introduction
Comparison operators help us check if things are equal, bigger, or smaller. This helps the computer decide what to do next.
Comparison operators help us check if things are equal, bigger, or smaller. This helps the computer decide what to do next.
value1 == value2 value1 === value2 value1 != value2 value1 !== value2 value1 > value2 value1 >= value2 value1 < value2 value1 <= value2
Use === and !== for exact matches including type.
Use == and != for loose comparison (not recommended).
== checks value only, so 5 and '5' are equal. === checks value and type, so they are not equal.5 == '5' // true 5 === '5' // false
10 > 7 // true 3 <= 3 // true
'apple' !== 'orange' // true
This program compares numbers and strings using different comparison operators and prints the results.
const a = 10; const b = '10'; console.log(a == b); // true console.log(a === b); // false console.log(a > 5); // true console.log(a < 5); // false console.log(a != b); // false console.log(a !== b); // true
Always prefer === and !== to avoid unexpected results.
Comparison operators return true or false, which are useful in decisions.
Comparison operators check how two values relate to each other.
=== and !== check both value and type.
They help the program decide what to do next.
== checks value equality but ignores type, while === checks both value and type.=== is the strict equality operator that compares both value and type.=== -> Option D=== [OK]a is NOT equal to variable b in both value and type?!== checks if two values are not equal in value or type.a !== b is correct syntax; others are either loose inequality or invalid.a !== b -> Option A!== [OK]console.log(5 == '5');
console.log(5 === '5');
5 == '5'== converts types, so number 5 equals string '5', result is true.5 === '5'=== checks type too; number 5 is not string '5', result is false.== true, === false [OK]if (a = 10) {
console.log('Equal');
} else {
console.log('Not equal');
}= assigns value 10 to a, not compares it.= with === to compare value and type correctly.=== instead of = -> Option Cscore is between 50 and 100 inclusive. Which expression correctly uses comparison operators to do this?50 <= score <= 100 as in math.score >= 50 && score <= 100 to check both conditions separately.score >= 50 && score <= 100 -> Option APass the test and this pattern moves unknown