JavaScript 检查全局变量是否存在

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 检查全局变量是否存在相关的知识,希望对你有一定的参考价值。

/* if (globalVariable) {

But this wouldn't work. That code is actually checking to see if the defined variable globalVariable has a null value. If the variable has not been defined, that code will cause an error.

Instead, here is the code that will check for the presence of a global variable:
*/
if (window.globalVariable) {

以上是关于JavaScript 检查全局变量是否存在的主要内容,如果未能解决你的问题,请参考以下文章