Ternary operators in JavaScript without an "else"

asked15 years ago
last updated5 years ago
viewed245.6k times
Up Vote235Down Vote

I've always had to put null in the else conditions that don't have anything. Is there a way around it? For example,

condition ? x = true : null;

Basically, is there a way to do the following?

condition ? x = true;

Now it shows up as a syntax error. FYI, here is some real example code:

!defaults.slideshowWidth ? defaults.slideshowWidth = obj.find('img').width()+'px' : null;