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&copy; 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 发布文章使用:只允许注册用户才可以访问!


最新文章

  1. 47个过程(PMBOK2008)
  2. kendo-ui学习笔记(一)
  3. float、double的有效位数
  4. C#--异步显示工作进度
  5. static和extern对函数的作用
  6. FCM算法
  7. PHP同一个IP绑定多个域名(六)
  8. Linux大文件传输(转)
  9. eclipse @ 注释为何一写就报错
  10. Trailing Zeroes (III)
  11. P1378 油滴扩展
  12. git错集
  13. [Android] Android Error: Suspicious namespace and prefix combination [NamespaceTypo] when I try create Signed APK
  14. Redhat 7 开通防火墙端口
  15. C - CodeCoder vs TopForces Gym - 101142C (连通块+思维)
  16. 数据结构c++实现代码-链表
  17. NodeJS 连接接MySQL
  18. BZOJ4785 ZJOI2017树状数组(概率+二维线段树)
  19. 基于GTID环境的数据恢复
  20. iOS 11开发教程(二十一)iOS11应用视图美化按钮之实现按钮的响应(1)

热门文章

  1. MySQL设计之Schema与数据类型优化
  2. MySQL调优用户监控之show processlist
  3. 美团配送A/B评估体系建设与实践
  4. Java并发练习
  5. 2021年,python的入门基础-----基础一
  6. MySQL集群之MyCat
  7. oss-server 小型对象存储系统
  8. 小心 Enum Parse 中的坑
  9. Pytest(5)美化插件进度条pytest-sugar
  10. POJ-3208 Apocalypse Someday (数位DP)