抓住不合适的价值并不适用于JS

时间:2014-05-11 07:58:15

标签: javascript

console.log(myVar),我看到未定义,所以

if(myVar == 'undefined') alert('undefined)

但警报没有弹出,有什么问题?如何在javascript中捕获undefined?

1 个答案:

答案 0 :(得分:0)

  1. 您忘记了'结束传递给alert
  2. 的字符串
  3. 您正在将值myVar与字符串'undefined'进行比较。您需要比较typeof变量,或者需要与值undefined进行比较