Special Operators

Special Operators

?: (Conditional operator)

The conditional operator is the only MetaScript operator that takes three operands. This operator is frequently used as a shortcut for the if statement.

Syntax

condition ? expr1 : expr2

Parameters

 

condition

An expression that evaluates to true or false

expr1, expr2

Expressions with values of any type.

Description

If condition is true, the operator returns the value of expr1; otherwise, it returns the value of expr2. For example, to get a different message based on the value of the isMember variable, you could use this statement:

s = "The fee is " + (isMember ? "$2.00" : "$10.00");


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.