Javascript,條件(三元)運算子,隱含比較

 A ? B : C 


如果A是TRUE,則return B,如果不是則return C

例:
document.write((4===1)?"true":"false");
得到false

document.write((4===1)?"正確":"錯誤");
得到錯誤

document.write((4===1)?"香蕉":"檸檬");
得到檸檬

留言