在==(相等)判断中,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. webloader上传图片详细教程/使用thinkphp5.0(原创)

    这个插件对后端程序员相当友好,无论是JAVA还是PHP,抑或python,基本只需要一句代码就能完成上传并且预览的效果,先上效果图,让你们眼馋一下 废话不说,直接撸代码,前端代码如下: <htm ...

  2. (一)安装openvpn服务器端

    环境 centos版本 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 关闭cento ...

  3. sonarQube Github pull request扫描代码

    参考官方地址:https://docs.sonarqube.org/display/PLUG/GitHub+Plugin 运行环境:sonarQube6.2 + sonarScanner2.8 近来, ...

  4. 31、Django实战第31天:我的课程

    1.编辑usercenter-mycourse.html继承usercenter-base.html 2.编辑users.views.py ... from operation.models impo ...

  5. 利用 ildasm 修改被编译后DLL文件

    在开发中遇到这样一个场景,需要修改一个dll文件(.NET程序集)中某些地方的类型名称,但没有源代码,只能修改IL代码. 操作步骤如下: 1. 运行ildasm ildasm是由微软提供的.NET程序 ...

  6. 浅谈单页应用和多页应用——Vue.js向

    浅谈单页应用和多页应用--Vue.js向 多页面 多页面应用:每次页面跳转,后台都会返回一个新的HTML文档,就是多页面应用. 在以往传统开发的应用(网站)大多都是多页面应用,路由由后端来写. 页面跳 ...

  7. CentOS 安装 Zookeeper 版本任选

    Zookeeper下载地址各种版本自己选择: https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ Zookeeper 3.4.13版本下载地址 ...

  8. intellij idea android错误: Missing styles. Is the correct theme chosen for this layout?

    Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layou ...

  9. python基础-函数之装饰器、迭代器与生成器

    1. 函数嵌套 1.1 函数嵌套调用 函数的嵌套调用:在调用一个函数的过程中,又调用了其他函数 def bar(): print("from in the bar.") def f ...

  10. golang设计模式-成员变量赋值

    常见golang的struct赋值有两种: 1)定义变量同时初始化 val := &Options{ UID:int(1), } 2)先定义变量,再赋值 val := new(Options) ...