+ 2

? sth : sth

What does this mean? return n % 2 == 1 ? '1' : '0';

10th Mar 2017, 4:47 PM
Nara
Nara - avatar
2 Answers
+ 6
this is a conditional operator. it is the same as writing :- if(n % 2 == 1) return '1'; else return '0';
10th Mar 2017, 4:51 PM
Nikunj Arora
Nikunj Arora - avatar
+ 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 :
11th Mar 2017, 6:15 AM
Michael Szczepanski
Michael Szczepanski - avatar