MENU
Conditional (ternary) Operator
The ?: ternary operator offers a compact way of evaluating conditional expressions in place of 'if' statements (8.3.1). One of its strengths is that it permits a continuation when the prior expressions all evaluate to false. Binary expressions after the true expression are not evaluated.
var n = 50;
var c = (n > 1000) ? "thousands"
: (n > 100) ? "hundreds"
: (n > 10) ? "tens"
: "a few";
console.log(c);tens