JavaScript Comparison and Logical Operators

1/21/2020 7:08:44 AM

In the JavaScript have comparison and logical operators.  When we compare element then we use comparison operators. Comparison operators are very important to implement any kind of application. Suppose we create a form then we check the “Email” field then we need to check ‘@’ and ‘.’ Symbol then we use the comparison operators. Comparison operators allows return ‘true’ or ‘false’. Given bellow the Comparison operators symbol: >, <, >=, <=, ===, and !== .
On the other hand, Logical operators are also important to compare between two or more element compare at a time. Given bellow the Logical operators symbol: &&, ||, and ! .
We can also work with Comparison and Logical Operators at a time or same line of code. Given bellow the example code and explain the code:

<!DOCTYPE html>
<script type="text/javascript">
// JavaScript Comparison and Logical Operators
//create three object
  var farhan = {firstName:"Farhan", lastName:"Sakib", age:25, eyeColor:"blue"};
  var reza = {firstName:"Reza", lastName:"Karim", age:28, eyeColor:"black"};
  var tofile = {firstName:"Tofile", lastName:"Ahmed", age:26, eyeColor:"blue"};
//compare betwn two persone
if (farhan["age"]<reza["age"]) {
 console.log("Reza is older then farhan");
//match must and should two
if (farhan["age"]<reza["age"] && farhan["eyeColor"]!=reza["eyeColor"]) {
 console.log("Deferrent eye color between farhan and sakib");
//match only one then excicute
if (farhan["eyeColor"]==tofile["eyeColor"] || farhan["age"]==tofile["age"]) {
console.log("There eye color are same !");

In this code we create three-person object and compare the parson property and print the message. Also, we use the logical Operators as well as we use the compare operator then if the condition is full fill then we print the output into console windows.