The correct is return a<b?-1: (a>b? 1 :0)
var a="a", b=1; a<b ? -1 : (a>b ? 1 : 0); // 0
The switch and if statements would return undefined in these cases. Or others threw an error if none of the conditions matched, that would work too.
var a="a", b=1; a<b ? -1 : (a>b ? 1 : 0); // 0
The switch and if statements would return undefined in these cases. Or others threw an error if none of the conditions matched, that would work too.