The conditional operator is the most powerful operator in JavaScript and is often used as a concise form of the if statement.

The conditional operator is the only ternary operator that is used with a question mark (?). And a colon (:) to separate the three expressions.

If the Boolean value of the first expression is true, then the value of the second expression is returned; otherwise, the value of the third expression is returned directly, with the syntax: x? A: b.

A conditional operator can be converted to a conditional structure or to a logical expression:

// if(typeof x! = "undefined"){ x = x; }else{ x = 0; } console.log(x); // 2. Logical expression conversion (typeof Y! = "undefined") && (y = y) || (y = 0); console.log(y);

Example:

var num1 = 79;  
var num2 = 85;  
var compare = num1 > num2 ? num1 : num2;  
comsole.log(compare);