if

Returns the first value if the condition is true; otherwise, returns the second value.
Accepts
Returns
Syntax
if(condition, ifTrue, ifFalse) condition.if(ifTrue, ifFalse)
Operator

? :


if(
    1 + 1 == 3, 
    "1 plus 1 equals 3!", 
    "1 plus 1 does not equal 3!"
)if(
    /* Check if 1 plus 1 equals 3 */
    1 + 1 == 3,

    /* If it does, display "1 plus 1 equals 3!" */
    "1 plus 1 equals 3!",

    /* Otherwise display "1 plus 1 does not equal 3!" */
    "1 plus 1 does not equal 3!"
)
=
1 plus 1 does not equal 3! "1 plus 1 does not equal 3!"