Welcome ðŸŽ‰

logo

ReactLMS

Search
Light Mode
Contact Us

5 min to read

Contact us

No results for your search.
Sorry, an unexpected error occurred

Concept


In the JavaScript programming language, comparisons between values are an important part of the programming process. It plays a role in deciding the branching behavior to be performed.


Equal and not equal comparison


Equal (==) comparison is used to check if two values are equal.

var x = 5;
var y = 10;

console.log(x == y);  // false
console.log(x == 5);  // true






The not equal operator (!=) is used to check if two values are different or not.

var x = 5;
var y = 10;

console.log(x != y);  // true
console.log(x != 5);  // false







Strict and non-strict comparison


Strict comparison (===) is used to check if two values are equal and of the same data type.

var x = 5;
var y = '5';

console.log(x === y);  // false
console.log(x === 5);  // true






Non-strict inequality (!==) is used to check if two values are different or different data types. For example:

var x = 5;
var y = '5';

console.log(x !== y);  // true
console.log(x !== 5);  // false







Comparisons


Greater than (>) comparison is used to check if a value is greater than another value. Less than (<) comparison is used to check if a value is less than another value.

var x = 5;
var y = 10;

console.log(x > y);   // false
console.log(x < y);   // true






Greater than or equal to (>=) comparison is used to check if a value is greater than or equal to another value. Less than or equal to (<=) comparison is used to check if a value is less than or equal to another value.

var x = 5;
var y = 10;

console.log(x >= y);   // false
console.log(x <= y);   // true







Logical comparison


In JavaScript, we can combine multiple comparison expressions together to create logical comparison expressions. We have three main logical comparison operators:

var x = 5;
var y = 10;
var z = 15;

console.log(x < y && y < z);     // true
console.log(x < y || y > z);     // true
console.log(!(x == y));          // true








Read more
On This Page