Is there a standard function to check for null, undefined, or blank variables in JavaScript?

前端 未结 30 4245
眼角桃花
眼角桃花 2020-11-21 23:37

Is there a universal JavaScript function that checks that a variable has a value and ensures that it\'s not undefined or null? I\'ve got this code,

30条回答
  •  感动是毒
    2020-11-22 00:20

    Try With Different Logic. You can use bellow code for check all four(4) condition for validation like not null, not blank, not undefined and not zero only use this code (!(!(variable))) in javascript and jquery.

    function myFunction() {
        var data;  //The Values can be like as null, blank, undefined, zero you can test
    
        if(!(!(data)))
        {
            alert("data "+data);
        } 
        else 
        {
            alert("data is "+data);
        }
    }
    

提交回复
热议问题