js & void & undefined & null
js & void & undefined & null

The void operator evaluates the given expression and then returns undefined.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
void function test() {
console.log('boo!');
// "boo!"
return "undefined === void 0 && null == void 0";
}();
try {
test();
} catch (e) {
console.log(e);
// ReferenceError: test is not defined
}
/*
"boo!"
ReferenceError: test is not defined
*/
void 2 == '2';
// false
void (2 == '2');
// undefined

void
void 0;
// undefined
undefined === void 0;
// true
null === void 0;
// false
null == void 0;
// true
undefined == null;
// true
// undefined == false;
false
null == false;
// false
const log = console.log;
let varVoid = void 0;
log(`var void =`, varVoid);
// var void = undefined
undefined
const log = console.log;
let varDefault;
log(`var default =`, varDefault);
// var default = undefined
null
const log = console.log;
let vaNull = null;
log(`var null =`, vaNull);
// var null = null
html
<body>
<header>
<h1>void(js expression)</h1>
</header>
<main>
<article>
<section>
<div>
<a href="javascript:void(0);">
Click here to do nothing
<span>javascript:void(0);</span>
</a>
</div>
<div>
<a href="javascript:void(1);">
Click here to do nothing
<span>javascript:void(1);</span>
</a>
</div>
<div>
<a href="javascript:void(true);">
Click here to do nothing
<span>javascript:void(true);</span>
</a>
</div>
<div>
<a href="javascript:void(document.body.style.backgroundColor='green');">
Click here for green background
</a>
</div>
<div>
<a href="javascript:void(document.body.style.backgroundColor='white');">
Click here for init background
</a>
</div>
</section>
</article>
</main>
<footer>
<p>copyright© xgqfrms 2020</p>
</footer>
<!-- js -->
<script>
const log = console.log;
</script>
</body>
https://codepen.io/xgqfrms/pen/poyYGZw
refs
TypeScript
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
js & void & undefined & null的更多相关文章
- js中undefined,null,NaN的区别
1.类型分析: js中的数据类型有undefined,boolean,number,string,object等5种,前4种为原始类型,第5种为引用类型.var a1;var a2 = true;va ...
- 20180911 关于页面加载顺序引发的JS的undefined/null错误
引用: 百度知道-HTML+JavaScript执行顺序问题 这是我在学习JS滚动播放图片案例意外遇到的一个问题,代码完成后console弹出错误警告: Uncaught TypeError: Can ...
- js判断undefined类型,undefined,null,NaN的区别
js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined 所以自作聪明判断 ...
- js判断undefined类型,undefined,null, 的区别详细解析
js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined所以自作聪明判断 var reVal ...
- html5 -js判断undefined类型
js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined所以自作聪明判断 var reVal ...
- js基础篇——call/apply、arguments、undefined/null
a.call和apply方法详解 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象 ...
- js中的null和undefined
大部分编程语言一般有一个表示“无”的值,而js中却有两个,null和undefined.所以查了一些资料,小结在此,以便查阅. js中的变量有两大类,基本的值类型,引用类型.其中值类型分为:Undef ...
- 【学习笔记】js中undefined和null的区别和联系
在JavaScript中存在这样两种原始类型:Null与Undefined.这两种类型常常会使JavaScript的开发人员产生疑惑,在什么时候是Null,什么时候又是Undefined? Undef ...
- js判断undefined和null
js判断undefined var exp = undefined; if (typeof(exp) == "undefined") { alert("undefined ...
随机推荐
- 提取当前文件夹下的所有文件名.bat(Windows批处理文件)
@echo off dir /s/b *.* > 文件名.txt exit
- MySQL中 utf8与utf8mb4的区别
MySQL中 utf8与utf8mb4的区别 一.简介 MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在 ...
- CI/CD 最佳实践的基本原则 互联网后端架构 2020-10-04
https://mp.weixin.qq.com/s/UfGmCueEm8n2jdegng1F_g CI/CD 最佳实践的基本原则 互联网后端架构 2020-10-04
- centralized collectors 中心化 采集器
Fluent Bit https://fluentbit.io/ FluentBit is an open source specialized data collector. It provides ...
- 思考gRPC :为什么是HTTP/2
Introducing gRPC Support with NGINX 1.13.10 - NGINX https://www.nginx.com/blog/nginx-1-13-10-grpc/ 思 ...
- 编译安装 codeblocks 20.03 mips64el
期末考试要用哦,不然谁会愿意去踩这么多坑. qaq 龙梦 Fedora28 中有 codeblocks 17.12,但是 Ctrl-v 粘贴会闪退,导致压根不能用.Bing了一下发现这其实是 code ...
- 阿里一面,给了几条SQL,问需要执行几次树搜索操作?
前言 有位朋友去阿里面试,他说面试官给了几条查询SQL,问:需要执行几次树搜索操作?我朋友当时是有点懵的,后来冷静思考,才发现就是考索引的几个基础知识点~~ 本文我们分九个索引知识点,一起来探讨一下. ...
- mysqld_exporter的源码分析和定制化(单个mysqld_exporter监控多个数据库实例)
mysqld_exporter是prometheus官方提供的用于监控mysql运行状态的exporter.其相关信息可以参考:https://github.com/prometheus/mysqld ...
- SQL中字符串截取函数(SUBSTRING)
1.left(name,4)截取左边的4个字符 列: SELECT LEFT(201809,4) 年 结果:2018 2.right(name,2)截取右边的2个字符 SELECT RIGHT(201 ...
- 2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (8/10)
$$2013-2014\ ACM-ICPC,\ NEERC,\ Eastern\ Subregional\ Contest$$ \(A.Podracing\) 首先枚举各个折现上的点,找出最小宽度,然 ...