javascript如何判断一个变量未定义

4次阅读

共计 231 个字符,预计需要花费 1 分钟才能阅读完成。

undefined

永远不要直接使用 undefined 进行变量判断;

使用 typeof 和字符串 ’undefined’ 对变量进行判断。

// not good
if (person === undefined) {...}

// good
if (typeof person === 'undefined') {...}

摘自腾讯的代码规范文档
http://alloyteam.github.io/CodeGuide/index.html

http://alloyteam.github.io/Co…

正文完
 0