当前位置:网站首页>趣-关于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,但是我们业务上的东西还是要追求细致和严谨.
边栏推荐
- Getting started with pytest ----- allow generate report
- Shell input a string of numbers to determine whether it is a mobile phone number
- 偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
- Summary of Android interview questions of Dachang in 2022 (II) (including answers)
- 微信小程序获取手机号
- Spark accumulator and broadcast variables and beginners of sparksql
- Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
- Quick start of Hongmeng system
- [rapid environment construction] openharmony 10 minute tutorial (cub pie)
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
猜你喜欢

酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅

What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?

Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology

【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias

Distinguish between basic disk and dynamic disk RAID disk redundant array

Automatic operation and maintenance sharp weapon ansible Foundation

Awk command exercise
![[introduction to MySQL] the first sentence · first time in the](/img/1e/2401d821b1008922bc5f8a15de31f9.png)
[introduction to MySQL] the first sentence · first time in the "database" Mainland

FlutterWeb瀏覽器刷新後無法回退的解决方案
![[ASM] introduction and use of bytecode operation classwriter class](/img/0b/87c9851e577df8dcf8198a272b81bd.png)
[ASM] introduction and use of bytecode operation classwriter class
随机推荐
adb常用命令
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
Interview assault 63: how to remove duplication in MySQL?
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
Grafana 9 is officially released, which is easier to use and more cool!
pip install pyodbc : ERROR: Command errored out with exit status 1
Virtual machine startup prompt probing EDD (edd=off to disable) error
Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
kivy教程之在 Kivy 中支持中文以构建跨平台应用程序(教程含源码)
Automatic operation and maintenance sharp weapon ansible Foundation
BearPi-HM_ Nano development board "flower protector" case
Mysqlimport imports data files into the database
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
2022年大厂Android面试题汇总(一)(含答案)
OpenCV中如何使用滚动条动态调整参数