js 中比较 undefined

// x has not been declared before
if (typeof x === 'undefined') { // evaluates to true without errors
   // these statements execute
}
//如果未定义变量,那么会出现引用错误
if(x === undefined){ // throws a ReferenceError

}
posted @ 2016-09-14 11:30  特洛伊-Micro  阅读(399)  评论(0)    收藏  举报