3 ms·
both fragments are incorrect for NaN... The correct is return a<b?-1: (a>b? 1 :0)
by xxs 7y ago
both fragments are incorrect for NaN...
The correct is
return a<b?-1: (a>b? 1 :0)
- crznp 7y agovar a=NaN, b=1; a<b ? -1 : (a>b ? 1 : 0); // 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.