是否有標準函數檢查JavaScript中的null,undefined或空白變量?

問題:

Is there a universal JavaScript function that checks that a variable has a value and ensures that it's not undefined or null ? 是否有通用的JavaScript函數可檢查變量是否具備值並確保其undefined或爲null I've got this code, but I'm not sure if it covers all cases: 我有如下代碼,可是不肯定是否能涵蓋全部狀況: 函數

function isEmpty(val){
    return (val === undefined || val == null || val.length <= 0) ? true : false;
}

解決方案:

參考一: https://stackoom.com/question/N8mc/是否有標準函數檢查JavaScript中的null-undefined或空白變量
參考二: https://oldbug.net/q/N8mc/Is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in-JavaScript
相關文章
相關標籤/搜索