当前位置:网站首页>趣-关于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,但是我们业务上的东西还是要追求细致和严谨.
边栏推荐
- Solr appears write Lock, solrexception: could not get leader props in the log
- 学 SQL 必须了解的 10 个高级概念
- C WinForm series button easy to use
- In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
- Spark calculation operator and some small details in liunx
- MySQL 8 sub database and table backup database shell script
- 8位MCU跑RTOS有没有意义?
- The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
- node の SQLite
- 基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
猜你喜欢
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
OliveTin能在网页上安全运行shell命令(上)
node の SQLite
【MySQL入门】第三话 · MySQL中常见的数据类型
Uipath browser performs actions in the new tab
JMeter interface test response data garbled
C # nanoframework lighting and key esp32
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
Unity粒子特效系列-闪星星的宝箱
Pytorch extract middle layer features?
随机推荐
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
Solr appears write Lock, solrexception: could not get leader props in the log
How to submit data through post
SAP UI5 框架的 manifest.json
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
Getting started with pytest ----- allow generate report
Hongmeng introduction and development environment construction
分布式不来点网关都说不过去
Basic configuration and use of spark
Uipath browser performs actions in the new tab
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
Easy introduction to SQL (1): addition, deletion, modification and simple query
Getting started with pytest ----- test case pre post, firmware
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
【MySQL入门】第三话 · MySQL中常见的数据类型
Flink analysis (II): analysis of backpressure mechanism
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes