文章内容
2022/2/25 15:56:24,作 者: 黄兵
JavaScript true 的一些情况
如果结果不为以下值则为 true:
- null
- undefined
- NaN
- empty string ("")
- 0
- false
上面的值代码了会出现 false 的情况,具体 ECMAScript 规范已经定义了会出现 Boolean 的情况 。
此外,如果您不知道变量是否存在(这意味着,如果它已声明),您应该检查typeof 操作。例如:
if( typeof foo !== 'undefined' ) { // foo could get resolved and it's defined }
参考资料:
1、Is there a standard function to check for null, undefined, or blank variables in JavaScript?
爬虫系列:采集 JavaScript
Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
评论列表