Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Comparison Operators

JS Comparison Operators

Comparison operators are used in logical statements to determine equality or difference between variables or values and return either true or false.

Comparison operators can be used in conditional statements to compare values and take action depending on the result:

Let say x = 5

Operator Description Example Result
== equal to x == 8 false
== equal to x == 5 true
== equal to x == "5" true
=== equal value and equal type x === 5 true
=== equal value and equal type x === "5" false
!= not equal x != 8 true
!== not equal value or not equal type x !== 5 false
!== not equal value or not equal type x !== "5" true
> greater than x > 8 false
< greater than x < 8 true
>= greater than x >= 8 false
<= greater than x <= 8 true
					 
        
          if (age < 18) {
            text = "Too young to vote";
          }
        
      
JS Logical Operators

Let say x = 6 and y = 3

Operator Description Example Result
&& AND (x < 10 && y > 1) true
|| OR (x == 5 || y == 5) false
! NOT !(x == y) true
Ternary Operators

JavaScript also contains a conditional (ternary) operator that assigns a value to a variable based on some condition.

Syntax

variablename = (condition) ? value1:value2

Example

					 
        
          let voteable = (age < 18) ? "Too young" : "Old enough";
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved