JavaScript syntax question: conditional list element?
This is probably an easy one for you Javascript wonks...
I'm looking for a way to conditionally include or exclude a list element -- in Perl this is easy, how's it done in Javascript?
x = dosomething("yadda", (sometest() ? "yep" : ()), "blah");
So if sometest() returns TRUE then then we dosomething("yadda","yep","blah") otherwise we dosomething("yadda","blah").
Is that possible in Javascript?
Looking for an optional empty list element
Well that's not quite what I'm after -- I'm hoping to include two or three elements, not choose which of two values to use for the second element.
In Perl, this is simply
$x = dosomething(
"yadda",
(sometest() ? "yep" : ()),
"blah",
);
Where the () signifies an empty list, so that the argument list is either a two-item "yadda","blah" or a three-item "yadda","yep","blah". (And the trailing comma is a great convenience for future cut-and-paste of lines of code.)
Does javascript have an empty-list expression like () in perl?