How can I determine if a variable is 'undefined' or 'null'?

前端 未结 30 1522
耶瑟儿~
耶瑟儿~ 2020-11-22 03:30

How do I determine if variable is undefined or null?

My code is as follows:

var EmpN         


        
30条回答
  •  鱼传尺愫
    2020-11-22 04:06

    I run this test in the Chrome console. Using (void 0) you can check undefined:

    var c;
    undefined
    if (c === void 0) alert();
    // output =  undefined
    var c = 1;
    // output =  undefined
    if (c === void 0) alert();
    // output =   undefined
    // check c value  c
    // output =  1
    if (c === void 0) alert();
    // output =  undefined
    c = undefined;
    // output =  undefined
    if (c === void 0) alert();
    // output =   undefined
    

提交回复
热议问题