條件賦值語句:避免str爲null空值時使用

上面的語句等價於: str = str and string.lower(str)

若是a不爲null空值,則執行後面的賦值語句。
其語義以下:code

if(str != null){
    str = string.lower(str)
}


這樣能夠避免str爲null空值時,string.lower拋出錯誤。
若是str爲空,則等號右側的語句根本不會執行。string

相關文章
相關標籤/搜索