Syntax | Effect |
boolean.toString( ) | Returns a string representing the boolean, either "true" or "false". Example: true.toString −> "true" false.toString −> "false" |
Note: For C/C++ programmers: These operators are the same as in C and C++. |
Syntax | Effect |
! boolean | Logical negation. Examples: ! true −> false ! false −> true |
exp1 && exp2 | Returns true if both boolean expressions exp1 and exp2 are true. Otherwise, returns false. If exp1 is false, this expression immediately returns false without evaluating exp2, so any side effects of exp2 are not taken into account. Examples: true && true −> true true && false −> false false && whatever −> false; whatever is not evaluated. |
exp1 || exp2 | Returns true if either boolean expression exp1 or exp2 is true. Otherwise, returns false. If exp1 is true, this expression immediately returns true without evaluating exp2, so any side effects of exp2 are not taken into account. Examples: false || true −> true false || false −> false true || whatever −> true; whatever is not evaluated. |
condition ? exp1 : exp2 | If condition is true, this expression returns exp1; otherwise, it returns exp2. When condition is true, the expression exp2 is not evaluated, so any side effects it may contain are not taken into account. Similarly, when condition is false, exp1 is not evaluated. Examples: true ? 3.14 : whatever −> 3.14 false ? whatever : "Hello" −> "Hello" |