JavaScript checking for null vs. undefined and difference between == and ===

前端 未结 8 829
忘了有多久
忘了有多久 2020-11-22 16:53
  1. How do I check a variable if it\'s null or undefined and what is the difference between the null and undefined?<

8条回答
  •  半阙折子戏
    2020-11-22 17:15

    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)))
    {
       //If data has valid value
        alert("data "+data);
    } 
    else 
    {
        //If data has null, blank, undefined, zero etc.
        alert("data is "+data);
    }
    

    }

提交回复
热议问题