- they are used to compare between two values in the logical statements just like "if statements"
- this operators return a boolean value True or False
- lets assume the we have a value x=10 lets see this table :
Operator | Description | Example | Returned value |
== | compare the equality of value to x=1- | 1)x==10 2)x==8 |
1)True 2)False |
=== | compare the equality of value and type to x=10 | 1)x===10 2)x==="10" |
1)True 2)False |
!= | check if the value isnt equal to x=10 | 1)x!=4 2)x!=10 |
1)True 2)False |
!== | not equality of value and type of x=10 | 1)x!==4 2)x!==10 3)x!=="4" |
1)False 2)False 3)True |
> | check if a value is greater than x=10 | 1)x>100 2)x>9 |
1)False 2)True |
< | check if a value is smaller than x=10 | 1)x<9 2)x<100 | 1)False 2)True |
>= | if a value is greater than or equal to x=10 | 1)x>=10 2)x>=5 |
1)True 2)False |
<= | if a value is smaller than or equal to x=10 | 1)x<=5 2)x<=100 3)x<=10 |
1)False 2)False 3)True |
-How to use these operators:
- we said that these operators are used in the logical statements just like if statement lets see an example to check if the student is failed or not by comparing his mark if its smaller than 50:
if you dont know much about if and else statements you can check out this article If statements
-Logical operators:
x=10
Operator | Description | Example | Returned Value |
&& | And two comparison must return true | if(x>8 &&x==10) | true |
|| | at least one comparison must return true | if(x!=10 !=x>5) | true |
No comments:
Post a Comment