Javascript Comparators


Comparators are used to check whether a given condition is satisfied or not.If the given condition is satisfied then given condition is successfully operated.
Operator Description
== Checks if given value is equal or not.
!= Checks if given condition is not equals.Function executed only when value is not equals given value.
> Checks if value on left handside is greater than value on right handside or not.
< Checks if value on right hanside is greater than value on left handside or not.
>= Checks if value on left handside is greater than or equal value on right handside or not.
<= Checks if value on right hanside is greater than or equal to value on left handside or not.

Javascript Logical Operators


Operator Description
&& This logical operator is called AND operator.This operator allows a function to execute only if both the conditions are satisfied.
|| This logical operator is called OR operator.If any of two of given conditions satisfies then function is executed.
! This logical operator is called NOT operator.If a condition is true then this operator returns result as false and operation is not executed.


Example for comparator operators:

<!DOCTYPE html>
<html>
<head>
<title>
JAVASCRIPT COMPARATORS
</title>
</head>
<body>
<p id="show">
</p>
<script>
var x=110;
document.getElementById
("show").innerHTML=(x==67);
</script>
</body>
</html>

Output:

Here output is false because above condition never satisfies.

In same way other comparator examples can be solved by replacing operator == in above example.

Example for logical operators



Explaination:

<!DOCTYPE html>
<html>
<head>
<title>
JAVASCRIPT
</title>
</head>
<body>
<input id="salary" value="25000" />
<button type="button" onclick="myFunction()"> Check </button>
<p id="elg">
</p>
<script>
function myFunction(){
var salary,loan;
salary=document.getElement
ById("salary").value;
loan=(salary<25000)? "To less":"Enough";
document.getElementById
("elg").innerHTML=loan + " for loan.";
}
</script>
</body>
</html>