JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
Syntax
variablename=(condition)?value1:value2 |
Example
greeting=(visitor=="PRES")?"Dear President ":"Dear "; |
If the variable visitor has the value of "PRES", then the variable greeting will be assigned the value "Dear President " else it will be assigned "Dear".
0 comments: