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

前端 未结 8 808
忘了有多久
忘了有多久 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条回答
  •  旧时难觅i
    2020-11-22 17:29

    If your (logical) check is for a negation (!) and you want to capture both JS null and undefined (as different Browsers will give you different results) you would use the less restrictive comparison: e.g.:

    var ItemID = Item.get_id();
    if (ItemID != null)
    {
     //do stuff
    }
    

    This will capture both null and undefined

提交回复
热议问题