当前位置:网站首页>趣-关于undefined的问题
趣-关于undefined的问题
2022-07-06 09:53:00 【自由的音符】
对于
undefined
这个东西,平常开发中不少使用,但是我们真的搞懂了嘛?
今天,奇怪的知识点出现了
众所周知,undefined
是未定义,项目中常这样写:
//常用在初始化
let str = undefined
没什么问题!但是大厂中的大神(深井冰)会研究一些神奇的问题!制定一些规范,要想定义undefined就得这样写。
//大厂中是这样用
var str=void 0
这是结果
作用:这样是为了消除一些隐患
譬如:
//如果我们这么写就有问题
function log(){
var undefined=1//因为undefined不是一个关键字,可以这样定义
var a=undefined//再声明一个变量a,它的值是undefined
console.log(a)//打印什么呢???
}
这里的
undefined
用的不是全局变量里面的undefined
,而是这个声明的变量undefined
,所以这样一赋值就会出问题了,打印了1
。
总结:虽然这可能是js带设计之初,遗留的bug,但是我们业务上的东西还是要追求细致和严谨.
边栏推荐
- The art of Engineering
- Awk command exercise
- Why should Li Shufu personally take charge of building mobile phones?
- 在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
- Vscode replaces commas, or specific characters with newlines
- Debug xv6
- MySQL 8 sub database and table backup database shell script
- Flink analysis (II): analysis of backpressure mechanism
- MySQL error reporting solution
- What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
猜你喜欢
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
The NTFS format converter (convert.exe) is missing from the current system
Establishment of graphical monitoring grafana
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
Easy introduction to SQL (1): addition, deletion, modification and simple query
传统家装有落差,VR全景家装让你体验新房落成效果
Pytest learning ----- pytest confitest of interface automation test Py file details
学 SQL 必须了解的 10 个高级概念
Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
Pytorch extract middle layer features?
随机推荐
Concept and basic knowledge of network layering
[introduction to MySQL] third, common data types in MySQL
Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
FlutterWeb浏览器刷新后无法回退的解决方案
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
8位MCU跑RTOS有没有意义?
【MySQL入门】第三话 · MySQL中常见的数据类型
Flink analysis (I): basic concept analysis
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
SAP UI5 框架的 manifest.json
Awk command exercise
Kernel link script parsing
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
Appium automated test scroll and drag_ and_ Drop slides according to element position
In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
TCP connection is more than communicating with TCP protocol
Binary search strategy
Summary of study notes for 2022 soft exam information security engineer preparation
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology