js conditional code example

Example 1: js ternary

condition ? ifTrue : ifFalse

Example 2: javascript ternary operator

//ternary operator example:
var isOpen = true; //try changing isOpen to false
var welcomeMessage  = isOpen ? "We are open, come on in." : "Sorry, we are closed.";

Example 3: single if statement js true false

condition ? exprIfTrue : exprIfFalse

Example 4: javascript conditional ? :

//XCal - Javascript Inline Conditional Sample (condition brackets only for clarity)
//                           v-? = Conditional Operator
//                           v                  v-: = True/False result value separator
//Format =    v-Condition-v  ?  v-When True-v   :  v-When False-v
var vResult = (null == null) ? 'Condition True' : 'Condition False';
//vResult is now 'Condition True';

Example 5: ternary operator in javascript

FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",

Example 6: javascript conditional

// example:
age >= 18 ? `wine` : `water`;

// syntax:
// <expression> ? <value-if-true> : <value-if-false>