测试浏览器:chrome
当有父元素的子元素未定义时undefined和null均为true,类型为undefined
当元素赋给null后undefined和null均为true,类型为object,因此建议设置为null
当直接用未定义顶级元素x时,无论是x==undefined或if(x)都会报错
function log(o){
    console.log(o);
}
function lognull(o){
    log(o==undefined)
    log(o==null)
    log(typeof o)

}

var a={aa:'bb'}
var c=null;
lognull(a.ff)//未定义子元素不会报错
lognull(c)
//以下,未定义顶级元素会报错
lognull(d)
if(dd){ //Uncaught ReferenceError: dd is not defined
}
 
 
 
测试结果
true
true
undefined
true
true
object
 Uncaught ReferenceError: d is not defined
-------------------------
 全部代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title> <script type="text/javascript">
function log(o){
console.log(o);
}
function lognull(o){
log(o==undefined)
log(o==null)
log(typeof o)
}
function notHave(o){
if(o==undefined){return true;}
if(o==null){return true;}
// if((typeof o)==undefined){return true;}
return false;
} var a={aa:'bb'}
var c=null;
lognull(a.ff)//未定义子元素不会报错
lognull(c)
//以下,未定义顶级元素会报错
lognull(d)
if(dd){ //Uncaught ReferenceError: dd is not defined }
</script>
</head> <body>
</body>
</html>

最新文章

  1. JS--实现简单轮播(一)
  2. 【C语言】C语言函数
  3. php xdebug配置
  4. ORACLE PL/SQL编程详解
  5. loose coupling之函数签名
  6. (谷歌浏览器等)解决css中点击input输入框时出现外边框方法【outline:medium;】
  7. lintcode:数字组合I
  8. C++仿函数(functor)详解
  9. LINQ to Entities does not recognize the method &#39;System.DateTime ToDateTime(System.String)&#39; method
  10. chrome 开发人员工具
  11. textarea显示源代码
  12. UNIX网络编程——产生RST
  13. spring-security doc logout
  14. python-re模块-54
  15. Java多线程编程模式实战指南之Promise模式
  16. MySQL_select语句(不定时更新)
  17. C# httpRequest Soap请求
  18. HTML 练习 做简历表
  19. MyBatis 延迟加载 加载时机
  20. appium镜像设置

热门文章

  1. 求1+2+3.。。。n的和
  2. vue中的文件上传和下载
  3. [CSP-S模拟测试]:w(树上DP)
  4. Spring Boot学习一之Spring Beans和依赖注入
  5. wsl中加载git之后,发现文件是修改状态
  6. python,mock-server之moco
  7. Java必备主流技术流程图,写得非常好!
  8. HTML 使用CSS 如何去掉文本聚焦框 HTML 使用CSS 如何去掉文本聚焦框 : outline 值设为none 修改input、textarea输入框placeholder样式
  9. for循环(C语言型)语法
  10. 利用Kubernetes(K8S)部署JAVA项目