mdn ternary operator code example

Example 1: 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 2: single if statement js true false

condition ? exprIfTrue : exprIfFalse

Example 3: javascript conditional evaluation

if ( expression )
Here are some expressions and their result
	Undefined: false
	Null: false
	Boolean: the result equals the input argument (no conversion)
	Number: false if the argument is +0, -0, or NaN; otherwise true
	String: false if the argument is an empty string (length = 0); 
			otherwise true
	Object: true

Tags:

C Example