测试浏览器: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>

undefined null测试的更多相关文章

  1. js判断undefined类型,undefined,null,NaN的区别

    js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined   所以自作聪明判断       ...

  2. js判断undefined类型,undefined,null, 的区别详细解析

    js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined所以自作聪明判断 var reVal ...

  3. 字符串怎么换行 || 字符串中使用单引号时应该怎么写 || 保留两位小数 || 数字0在if中的意思是false || 什么情况下会会报undefined || null和undefined的区别 ||

    换行的字符串 "This string\nhas two lines" 字符串中使用单引号时应该怎么写 'You\'re right, it can\'t be a quote' ...

  4. js基础篇——call/apply、arguments、undefined/null

    a.call和apply方法详解 call方法: 语法:call([thisObj[,arg1[, arg2[,   [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象 ...

  5. 悟透Javascript undefined,null,"",0这四个值转换为逻辑值时就是false &this关键字

    话题一:undefined,null,"",0这四个值转换为逻辑值时就是false 也就是在if判断时会把上面的五个作为false来判断.但是它们的类型确是不尽相同的,如下所示. ...

  6. undefined null 各种值比较(面试题)

    undefined和null与任何有意义的值比较返回的都是false,但是null与undefined之间互相比较返回的是true. console.log(null == false); //fal ...

  7. JS中的undefined,null,"",0,'0'和false

    ){ console.log(); } '){ console.log() } '){ console.log() } if(false==0.0){ console.log() } if(false ...

  8. js & void & undefined & null

    js & void & undefined & null The void operator evaluates the given expression and then r ...

  9. JavaScript 中undefined,null,NaN的区别

    1.类型分析: js中的数据类型有undefined,boolean,number,string,object等5种,前4种为原始类型,第5种为引用类型.var a1;var a2 = true;va ...

随机推荐

  1. Pasha and Tea

    Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. A Bug's Life - poj2492

    Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

  3. 热经-北京中地时空数码科技有限公司-研发工程师(WEBGIS方向)

    一面: 登记,填写个人信息 笔试 选择题: HTML,CSS,JS 的选择题,都是基础题.其中有一道问哪个不是 document 的属性或方法,我在 bgColor 和 focus() 上面纠结了一下 ...

  4. 服务端:WCF服务层安全检查核心类

    using System.Data; using CSFrameworkV4_5.Common; using CSFrameworkV4_5.Core.SystemSecurity; using CS ...

  5. python3+django2 个人简单博客实现 -正在施工

  6. Nacos-服务注册地址为内网IP的解决办法

    最近在使用Spring Cloud Alibaba这一套微服务解决方案,但是在服务注册的时候,网关死活找不到微服务地址,自己的微服务通过网关怎么也访问不到. 查找原因 仔细一查才发现,网关去访问了一个 ...

  7. Java技术中的三大特性

    1.虚拟机                                Java虚拟机JVM(Java Virtual Machine)在Java编程里面具有非常重要的地位,约相当于前面学到的Jav ...

  8. 二、spring的IoC

    IoC的基本认识 Inversion of Control:控制反转,就是将对象的创建权反转交给spring IoC的好处 传统方式的程序编写,底层的实现切换了,需要修改源代码 使用spring之后, ...

  9. Centos防火墙设置与端口开放

    前言 最近在部署项目的时候遇到了一些问题,阿里云主机要配置安全组策略和端口.对于这点看到了一片好的博文,特此总结记录下. iptables 方法一 打开某个端口 // 开启端口 iptables -A ...

  10. deep features for text spotting 在linux,windows上使用

    做文本检测这个方向的同学应该都知道 deep features for text spotting 这篇ECCV14的文章. 用的是Matconvnet这个是深度学习框架来做文本检测,同时他还提供了代 ...