In this tutorial I’m going to learn how to use Comparison and logical operators in laravel. Comparison operators compare two values and give back a boolean value: eitherĀ trueĀ orĀ false. Comparison operators are used inĀ decision makingĀ andĀ loops.
| Operator | Description | Example | 
|---|---|---|
== | Equal to: true if the operands are equal | 5==5; //true | 
!= | Not equal to: true if the operands are not equal | 5!=5; //false | 
=== | Strict equal to: true if the operands are equal and of the same type | 5==='5'; //false | 
!== | Strict not equal to: true if the operands are equal but of different type or not equal at all | 5!=='5'; //true | 
> | Greater than: true if the left operand is greater than the right operand | 3>2; //true | 
>= | Greater than or equal to: true if the left operand is greater than or equal to the right operand | 3>=3; //true | 
< | Less than: true if the left operand is less than the right operand | 3<2; //false | 
<= | Less than or equal to: true if the left operand is less than or equal to the right operand | 2<=2; //true | 
Example 1: Equal to Operator
const a = 5, b = 2, c = 'hello';
console.log(a == 5);     // true
console.log(b == '2');   // true
console.log(c == 'Hello');  // false
Output:-

Not equal to !=
const a = 3,
b = 'hello';
// not equal operator
console.log(a != 2);
console.log(b != 'Hello');
Output:-

Strict equal to
const a = 2;
// strict equal operator
console.log(a === 2); // true
console.log(a === '2');
Output:-

Thanks for reading šš
[…] JavaScript Comparison and Logical Operators […]