Page 93 - DCAP202_Fundamentals of Web Programming
P. 93
Fundamentals of Web Programming
Notes
Task Make distinction between String expression and logical expression.
7.2.1 Conditional Expression
A conditional expression can have one of two values based on a condition. The syntax is (condition)
? val1 : val2 If condition is true, the expression has the value of val1, otherwise it has the value
of val2. You can use a conditional expression anywhere you would use a standard expression.
Example: Status = (age >= 18) ? “adult” : “minor”
This statement assigns the value “adult” to the variable status if age is eighteen or greater.
Otherwise, it assigns the value “minor” to status.
Self Assessment
Fill in the blanks:
11. An ........................... is any valid set of literals, variables, operators, and expressions that
evaluates to a single value.
12. The special keyword null denotes a ...........................
13. A expression can have one of two values based on a ...........................
14. ........................... expression evaluates to a character string
15. Variables that have not been assigned a value are undefined, and cannot be used without
a ........................... error.
7.3 Summary
An operator is a symbol (it can also be a word) that performs calculations, comparisons or
assignment on one or more values.
The most common operators are mathematical operators; +, -, /, *.
Same logic applies to Bitwise operators so they will become like <<=, >>=, >>=, &=, |= and
^=.
—. a++ increments a and returns the old value of a. ++a increments a and returns the new
value of a.
Increment operators may be applied before or after a variable.
There is an operator called conditional operator. This first evaluates an expression for a
true or false value and then execute one of the two given statements depending upon the
result of the evaluation.
The typeof is a unary operator that is placed before its single operand, which can be of any
type.
The precedence of operators determines the order they are applied when evaluating an
expression.
86 LOVELY PROFESSIONAL UNIVERSITY