当前位置:网站首页>趣-关于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,但是我们业务上的东西还是要追求细致和严谨.
边栏推荐
- JMeter interface test response data garbled
- 分布式不来点网关都说不过去
- 传统家装有落差,VR全景家装让你体验新房落成效果
- Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
- Single responsibility principle
- BearPi-HM_ Nano development board "flower protector" case
- MySQL stored procedure
- Smart street lamp based on stm32+ Huawei cloud IOT design
- scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
- Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
猜你喜欢

Grafana 9 is officially released, which is easier to use and more cool!

开源与安全的“冰与火之歌”

Interview shock 62: what are the precautions for group by?

Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark

How to use scroll bars to dynamically adjust parameters in opencv

The NTFS format converter (convert.exe) is missing from the current system

视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备

The solution that flutterweb browser cannot be rolled back after refreshing

Concept and basic knowledge of network layering

Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
随机推荐
The problem of "syntax error" when uipath executes insert statement is solved
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
Uipath browser performs actions in the new tab
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
connection reset by peer
8位MCU跑RTOS有没有意义?
Flink parsing (III): memory management
Spark calculation operator and some small details in liunx
Flink analysis (I): basic concept analysis
pip install pyodbc : ERROR: Command errored out with exit status 1
Mysqlimport imports data files into the database
How to output special symbols in shell
Flink parsing (VII): time window
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
The shell generates JSON arrays and inserts them into the database
Wordcloud colormap color set and custom colors
The NTFS format converter (convert.exe) is missing from the current system
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Huawei certified cloud computing hica
[rapid environment construction] openharmony 10 minute tutorial (cub pie)