We will also learn comparison operators.
There are two possible options for Boolean value:
- They are True or Yes
- They are False or No
So Boolean logic is simply writing a statement to evaluate the idea that the statement is either True or False and eventually, we will use this statement to actually run certain parts of our code if something is true and some other part of our code if something else is false
So we use these kinds of statement to evaluate something like if a person X logged in to some Website, that’s true or false or a person X has more than $15,000 balance in their bank account, that’s true or false.
Here is the chart below where we have using all the comparison operators.
Assuming A = 10
|>||Greater than||A > 20||False|
|>=||Greater than or equal to||A >= 10||True|
|<||Less than||A < -50||False|
|<=||Less than or equal to||A <= 100||True|
|==||Equal to||A == "10"||True|
|!=||Not equal to||A != "b"||True|
|===||Equal value and type||A === "10"||False|
|!==||Not equal value or equal type||A !== "10"||True|
So let’s start with simple example and assume A=10.
If you see the operator in above chart where it depicts that is A >20? Obviously, A’s value is 10 can’t be equal to 20, so definitely it evaluates the value to be false.
So here is another simple example, let suppose there is a variable A whose value is 10
A = 10
But when we comparing value of A to number 5 and assuming A is greater than and equal to 5.
We use ‘greater than and equal to sign’ >= when we are not sure about the exact value.
A >= 5
So it evaluate the value to be true.
We then comparing variable A to 5 number and saying value of A which is 10 is greater than and equal to 5 and it evaluate the output as a true.
We have learned comparison operators with some example.