• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JavaScript Comparision Operators

March 26, 2014 //  by Krishna Srinivasan//  Leave a Comment

Javascript Operators can be categorized as:

  1. Comparison operators
  2. Conditional Operators
  3. Logical Operators

All the above three return true/false value.

Comparison Operator

Comparison operators are also known as relational operators. They are used in conditional statements, especially in loops where result of comparison decides whether execution should proceed. Comparison operators are used to test true or false. They are also used in logical statements to determine difference between values. Comparison operator cannot be used directly to compare objects .It can be used to compare only references of the object not the data they contain. It can be overloaded in user defined types. If == is overloaded, !== must be overloaded and same rule is applied to pairs and =. The following table shows the comparison operators:

Operator Description
Equal(==) It returns true if two operands are equal otherwise false.
Strict equal(===) it returns true if operands are exactly equal.
Not equal(!=) It returns true if the operands are not equal.
Strict not equal(!==) returns true if the operands are not equal or not of same type.
Greater than(>) It returns true if left operand is greater than right operand.
Greater than or equal(>=) It returns true if left operand is greater than or equal to right operand.
Less than(<) It returns true if left operand is less than right operand.
Less than or equal(<=) It returns true if left operand is less than or equal to right operand.

Comparison operators can also be used in conditional statements to compare values as follows: Example:

[code lang=”html”] If(age<20)

b=”younger”;

[/code]

Conditional Operator

It is also known as Ternary operator. It assigns value to a variable based on some condition. It has following syntax:

[code lang=”html”] variablename= (condition)? expression1:expression2
[/code]

It contains following parameters. condition is boolean expression, expression1 is returned if condition is true and expression2 is returned if condition is false. Example:

[code lang=”html”] a=(age<20)?”younger”:”older”;
[/code]

Logical Operator

Logical operators are used with boolean values which determines logic between variables.

Operator Desscription Example
AND (&&) It returns expr1 if it can be converted to false ,otherwise returns expr2. expr1 && expr2
OR (||) It returns expr1 if it can be converted to true, otherwise returns expr2. expr1 || expr2
NOT (!) It returns false if single operand can be converted to true, otherwise returns true. expr1 && expr2

Category: JavaScriptTag: JavaScript Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « JSF 2 Button and Link Example
Next Post: JSF 2 PanelGrid and PanelGroup Example »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

np.zeros

A Complete Guide To NumPy Functions in Python For Beginners

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact