当前位置:网站首页>Explain the difference between void 0 and undefined
Explain the difference between void 0 and undefined
2022-06-11 06:56:00 【Xiaoman's code world】
I'm learning js Library or framework , I found that it was used in many places void 0, I studied it carefully .
void Operator
Evaluate a given expression , Then return undefined.
void Operators are usually used only to get undefined Original value , In general use void(0)( Equate to void 0). In the above case , You can also use global variables undefined Instead of .— Excerpt from MDN
let me put it another way void 0 and undefined It is equivalent. . as follows :


volid The following cannot be followed by undeclared variables , Otherwise, an error will be reported .
void+xxx All are undefined, So why are some tool Libraries 0 Well , Maybe for convenience .
void 0 And undefined
undefined Is an attribute of a global object . in other words , It is a variable in the global scope .undefined The initial value of is the original data type undefined;
In modern browsers (JavaScript 1.8.5/Firefox 4+), since ECMAscript5 Since the standard undefined One cannot be configured (non-configurable), Can't be rewritten (non-writable) Properties of . Even if this is not the case , Also avoid rewriting it . But in the local scope , It can be rewritten .
// Don't do this !
// Print 'foo string' PS: explain undefined The value and type of have changed
(function() {
var undefined = 'foo';
console.log(undefined, typeof undefined)
})()
// Print 'foo string' PS: explain undefined The value and type of have changed
(function(undefined) {
console.log(undefined, typeof undefined)
})('foo')
undefined It could be rewritten ,void 0 Will not be rewritten .
and void 0 No matter when it comes back undefined, Like to see , Use void 0 Instead of undefined It's safer , No mistakes .
边栏推荐
- client-go gin的简单整合六-list-watch二(关于Rs与Pod以及Deployment的完善)
- Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]
- 538. convert binary search tree to cumulative tree
- Dynamic import
- Do you use typescript or anyscript
- WPF data binding (IV)
- Comparison of DOM tags of wechat applet development (native and uniapp)
- Post exam summary
- 021 mongodb database from getting started to giving up
- 【Matlab印刷字符识别】OCR印刷字母+数字识别【含源码 1861期】
猜你喜欢

JS judge whether the year is a leap year and the number of days in the month

Use of qscriptengine class

ESP32学习笔记(49)——ESP-WIFI-MESH接口使用

617. merge binary tree

Stack -- one of two common linear structures of linear structure

Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?

网狐游戏服务器房间配置向导服务定制功能页实现

迅为干货 |瑞芯微RK3568开发板TFTP&NFS烧写(上)

Biweekly investment and financial report: capital rush yuan universe game

About the designer of qtcreator the solution to the problem that qtdesigner can't pull and hold controls normally
随机推荐
How exactly does instanceof judge the reference data type!
[probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen
538. convert binary search tree to cumulative tree
洛谷P1091合唱队形(最长上升子序列)
搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
3.1 naming rules of test functions
Whether the ZABBIX monitoring host is online
Difference between byte and bit
Leetcode hot topic 100 topic 11-15 solution
Post exam summary
数组去重。。。。
UEFI finding PCI devices
text-overflow失效
Practice: how to reasonably design functions to solve practical problems in software development (II) -- improving reusability
RGB-D Salient Object Detection withCross-Modality Modulation and Selection
socket. IO cross domain stepping pit
Check whether the filing information of the medical representative is correct
VTK vtkplane and vtkcutter use
The meaning and research significance of mathematical methodology
必读1:格局越大的人,越懂得说话