On our way to functions.
Before we get deeper into functions, we need to take a look at comparison operators and logical operators. These are the symbols used to tell you’re code what it needs to do and when it needs to do it.
We will start with the comparison operators.
“==” – Two equal signs become the “Is Equal To” comparison
“===”-Three equal signs become the “Is Exactly Equal To” comparison
“!=” – Exclamation point and equal sign becomes “Not Equal To”
“>” – Greater Than
“<” – Less Than
“>=”—Greater than or equal to
“<=”—Less than or equal to.
Then there are Logical Operators that return True or False based on the given conditions.
“&&”- Two Ampersands stands for “AND”. Will return true if both given conditions are true, otherwise false.
x = 4, y = 3
if (x + y == 7 && y + x== 7)
{
document.write(“Addition is Commutative.”); //Both conditions are true, print this line.
}
“||”—Two pipes stands for “Or”. This will return true if one or both of the compared conditions is true. It will return false if both conditions are false.
x = 4, y = 3
if(x > 5 || y<2)
{
// both conditions are false, so any code in here wouldn’t be executed.
}
“!”—The Exclamation point is used to represent “Not”. This will return the opposite of the logical value.
x = 4
!(x==4) Would return false, because “x” is equal to 4 is true..