在==(相等)判断中,null和undefined相等(它们也与自身相等),除此之外不与其他值相等

示例代码:

<!DOCTYPE html>
<html lang="zh"> <head>
<meta charset="UTF-8" />
<title>null和undefined相等比较</title>
</head> <body> <script type="text/javascript">
var a = null;
var b;
console.log(a == b); //true
console.log(a == null); //true
console.log(b == null); //true
console.log(a == false); //false
console.log(b == false); //false
console.log(a == ''); //false
console.log(b == ''); //false
console.log(a == 0); //false
console.log(b == 0); //false
</script>
</body> </html>

判断对象是null,Object,Date

const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
const isNull = Object.prototype.toString.call(value).toLowerCase() === '[object null]';
Object.prototype.toString.call(dateObj) !== '[object Date]'

null和undefined相等比较的更多相关文章

  1. 判断一个值是否为null或者undefined

    var a=null; var b=undefined; if(a===null){ //a==null alert("a=null") }else{ alert("a= ...

  2. null和undefined的一些区别

    读了阮一峰的博客,自己总结一下,便记录一篇博客 在javacript的基本类型中,有2种基本类型,只有1个值,便是null和undefined,都表示的是"无".在一定程度上是相等 ...

  3. JS中判断null、undefined与NaN的方法

    写了个 str ="s"++; 然后出现Nan,找了一会. 收集资料如下判断: 1.判断undefined: 代码如下: <span style="font-siz ...

  4. V8 的 typeof null 返回 "undefined" 的 bug 是怎么回事

    1997 年,IE 4.0 发布,带来的众多新特性中有一个对未来“影响深远”的 DOM API:document.all.在随后的 6 年里,IE 的市场占有率越来越高,直到 2003 年的 95%. ...

  5. 【阿里李战】解剖JavaScript中的 null 和 undefined

    在JavaScript开发中,被人问到:null与undefined到底有啥区别? 一时间不好回答,特别是undefined,因为这涉及到undefined的实现原理.于是,细想之后,写下本文,请各位 ...

  6. null和undefined区别

    undefined表示不存在的状态.没有定义的变量,没有定义的对象属性,没有return的函数的返回值等等都是undefined. null表示没有对象.使用上没有差别,只是根据大众的使用习惯,场合不 ...

  7. null、undefined、false、0相等性比较

    之前在看<JavaScript权威指南>的时候看到三个相等性比较的式子: null == undefined ;// ==>true undefined == false;// == ...

  8. null和undefined区别(转)

    目前,null和undefined基本是同义的,只有一些细微的差别. null表示"没有对象",即该处不应该有值.典型用法是: (1) 作为函数的参数,表示该函数的参数不是对象. ...

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

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

  10. js笔记——js里的null和undefined

    以下内容摘录自阮一峰的<语法概述 -- JavaScript 标准参考教程(alpha)>章节『5.null和undefined』,以做备忘. null与undefined都可以表示&qu ...

随机推荐

  1. docker从零开始网络(四 ) host网络

    使用主机网络 如果host对容器使用网络驱动程序,则该容器的网络堆栈不会与Docker主机隔离.例如,如果您运行绑定到端口80 host的容器并使用网络,则容器的应用程序将在主机IP地址的端口80上可 ...

  2. 我们应选择怎样的IT公司

    最近经常有朋友提问,同时收到几家公司的offer,应该如何选择,或者找工作的时候,找怎样的公司,我在这里阐述一下我的观点.但愿对朋友们有所帮助. 还是那句老话,选择什么样的公司,关键是你想要过什么样的 ...

  3. java 反射赋空值

    https://stackoverflow.com/questions/10087989/how-do-i-reflectively-invoke-a-method-with-null-as-argu ...

  4. hdu5737

    首先思考一个朴素的做法 将b[]维护成一个线段树套有序表,每次修改a[]用线段树+lazy tag 并在线段树的子区间上在有序表中二分更新这段区间中a[i]>=b[i]的值,复杂度O(nlog^ ...

  5. [centos6.5] yum makecache 连接错误的解决办法

    http://mirrors.163.com/.help/centos.html 访问这个就懂了

  6. 模板—数学—Lucas

    模板—数学—Lucas Code: #include <cstdio> #include <algorithm> using namespace std; #define N ...

  7. 训练指南 UVALive - 3415(最大点独立集)

    layout: post title: 训练指南 UVALive - 3415(最大点独立集) author: "luowentaoaa" catalog: true mathja ...

  8. 12、Flask实战第12天:子域名

    什么是子域名,我们的后台管理系统, 比如cms.heboan.com.配置子域名需要用到蓝图技术: 我现在buleprints下面创建一个cms.py 蓝图 from flask import Blu ...

  9. [BZOJ 4034] 树上操作

    Link: BZOJ 4034 传送门 Solution: 树剖模板题…… Code: #include <bits/stdc++.h> using namespace std; type ...

  10. 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...