How to check if a variable or object is undefined?

前端 未结 7 1563
Happy的楠姐
Happy的楠姐 2020-12-10 16:51

I always thought I could just check an undefined var by comparing it to undefined, but this is the error I get in the chrome console :

7条回答
  •  一整个雨季
    2020-12-10 17:46

    The variable called "jQuery" in your code has never been declared, so it will throw an error like "xxx(variable name) is not defined".

    You can use the typeof operator to check is a variable is undefined or not

    if (typeof(jQuery) == "undefined")
    

提交回复
热议问题