+ 2
? sth : sth
What does this mean? return n % 2 == 1 ? '1' : '0';
2 Answers
+ 6
this is a conditional operator. it is the same as writing :-
if(n % 2 == 1)
return '1';
else
return '0';
+ 4
its called a ternary operator, not a conditional operator.
the first segment is a test, before the ?
second arg is the true statement. if the test is true, run that if its false run the third arg, after :