JavaScript null check

前端 未结 8 1012
小鲜肉
小鲜肉 2020-12-04 06:20

I\'ve come across the following code:

function test(data) {
    if (data != null && data !== undefined) {
        // some code here
    }
}
         


        
8条回答
  •  感动是毒
    2020-12-04 06:48

    The simple way to do your test is :

    function (data) {
        if (data) { // check if null, undefined, empty ...
            // some code here
        }
    }
    

提交回复
热议问题