javascript/jquery判断是否为undefined或是null!

var exp = undefined;

if (typeof(exp) == "undefined")
{
    alert("undefined");
}

注意判断是否是undefined的时候一定要在两边加上引号,否则不成功(个人测试结果!)

typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"

原文地址:https://www.cnblogs.com/communist/p/5952905.html