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 ...
随机推荐
- jemeter断言和性能分析
一.添加断言 1.原因:检查是否有该结果,一般一个请求过去除了400和500的只要通过的都会代表请求成功,比如登录页面及时填写了错误密码,虽然会返回密码错误,但这个请求还是成功的,所以我们要添加断言, ...
- Linux内核[CVE-2016-5195] (dirty COW)原理分析
[原创]Linux内核[CVE-2016-5195] (dirty COW)原理分析-二进制漏洞-看雪论坛-安全社区|安全招聘|bbs.pediy.com https://bbs.pediy.com/ ...
- (Oracle)取当前日期的最近工作日
描述:现有一需求,日期表中存放了日期和是否节假日(0-工作日,1-节假日),现在需要取日期表中的最近的工作日.如2017/07/23(周日)最近的工作日应该是2017/07/21(周五). ...
- 轻型目录访问协议 ldap 公司内部网站的登录 单点登录
https://zh.wikipedia.org/wiki/轻型目录访问协议 轻型目录访问协议(英文:Lightweight Directory Access Protocol,缩写:LDAP,/ˈɛ ...
- Compile-time Dependency Injection With Go Cloud's Wire 编译时依赖注入 运行时依赖注入
Compile-time Dependency Injection With Go Cloud's Wire - The Go Blog https://blog.golang.org/wire Co ...
- 【Python网络编程】epoll用法
epoll发展进程 此处添加一下select.poll历程及其优缺点 原理 使用步骤 Create an epoll object--创建1个epoll对象 Tell the epoll object ...
- 理解前端模块概念:CommonJs与ES6Module
前言 现代前端开发每时每刻都和模块打交道.例如,在项目中引入一个插件,或者实现一个供全局使用组件的JS文件.这些都可以称为模块. 在设计程序结构时,不可能把所有代码都放在一起.更为友好的组织方式时按照 ...
- LOJ10065 北极通讯站
Waterloo University 2002 北极的某区域共有 n 座村庄,每座村庄的坐标用一对整数 (x,,y) 表示.为了加强联系,决定在村庄之间建立通讯网络.通讯工具可以是无线电收发机,也可 ...
- Linux内核poll/select机制简析
0 I/O多路复用机制 I/O多路复用 (I/O multiplexing),提供了同时监测若干个文件描述符是否可以执行IO操作的能力. select/poll/epoll 函数都提供了这样的机制,能 ...
- 十六:SpringBoot-自定义启动页,项目打包和指定运行环境
SpringBoot-自定义启动页,项目打包和指定运行环境 1.自定义启动页 2.打包配置 2.1 打包pom配置 2.2 多环境配置 3.环境测试接口 4.打包执行 4.1 指定模块打包 4.2 运 ...