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

前端 未结 8 807
忘了有多久
忘了有多久 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:30

    How do I check a variable if it's null or undefined

    just check if a variable has a valid value like this :

    if(variable)
    

    it will return true if variable does't contain :

    • null
    • undefined
    • 0
    • false
    • "" (an empty string)
    • NaN

提交回复
热议问题