JS判断变量是否已经定义


if
( callbackfun != "undefined" ) { callbackfun(); } //发现判断不出来,最后查了下资料要用typeof //方法: if ( typeof(callbackfun) != "undefined" ) { callbackfun(); }

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

原文地址:https://www.cnblogs.com/yun007/p/2883091.html