简单粗暴易懂。
var result = 0;
function test (a,b,c){
// result = ( a == 1) ? 0 : 1 ;
// result = ( a == 1) && (b == 1 ) ? 0 : 1 ;
// result = ( a == 1 ) || ( b == 1) ? 0 : 1;
// result = ( a == 1 ) ? b : a == 2 ? 0 : 1;
result = ( a == 1 ) ? 'one' : b == 2 ? 'two' : c == 3 ? 'three' : 4;
return result ;
}
console.log(test (3)); ?
附:
- x? y:z
- x是一个boolean类型,若x为true,结果显示y,若x为false,则结果显示z.