What is the best way to compare a value against 'undefined'?

前端 未结 6 1887
误落风尘
误落风尘 2020-12-16 21:57

Is there any differences between

var a;
(a == undefined)
(a === undefined)
((typeof a) == \"undefined\")
((typeof a) === \"undefined\")

Whi

6条回答
  •  一生所求
    2020-12-16 22:48

    I personally like to use

    [undefined, null].indexOf(variable) > -1
    

    to check also for null values.

提交回复
热议问题