Javascript Comparisons
comparision operators
how to use comparisons
logical operators
conditional operators
comparisions and logical operators are used to test for true or false
Comparision operators
Comparision operators are used in logical statements to determine equality or difference between variables or values
Operator Description
= = is equal to value... is equal to value
= = = is exactly eual to value and type
!= is not equal
> is grater than
< is less than
>= is greater than or equal to
<= is less than or equal to
How to use comparisions
Comparision operators can be used in conditional statements to compare values and taje action depending on the result.
if(age<18)
document.write("Too Young");
Logical Operators
Logical operators are used to determine the logic between variables or values
Operators Description
&& and
|| or
! not
Conditional Operator
Javascript also contains a conditional operator that assigns a value to a variable based on some conditions.
variablename=(condition)?value1:value2
ex:
greeting=(visitor=="Pres")?Dear President ":"Dear";
If the variable visitor has the value of "Pres", then the variable greeting will be assigned the value "daer president" else it will be assigned "dear"
No comments:
Post a Comment