Does Javascript support the short ternary (rather, variation of) as in PHP? Does Javascript support the short ternary (rather, variation of) as in PHP? javascript javascript

Does Javascript support the short ternary (rather, variation of) as in PHP?


Yes, use ||. Unlike PHP, JavaScript's || operator will return the first non-falsy value, not a normalized boolean.

foo || 'world'


var myFunc = function(foo) {  foo = foo || 'my default value for foo';}