当前位置:网站首页>null和undefined的区别
null和undefined的区别
2022-04-23 06:18:00 【十九(一拖再拖)】
null和undefined的区别
null:代表空对象
undefined:代表变量未赋值
总结:
- 定义变量但未分配值时,输出undefined
- 变量可以指定为 null,但不能分配给 undefined
- 当变量设置为 null 时,类型为 object
例子:
️:当定义一个变量但未对其进行赋值时,输出 undefined。
var a;
console.log(a)
output:undefined
如果未创建变量就进行使用,输出 a is not defined
console.log(a)
output:Uncaught ReferenceError: a is not defined;
️:为变量赋值时:
可以赋值为 null,
但不可以赋值成 undefined
var a = undefind;
console.log(a)
output:undefind is not defined
var a = null;
console.log(a)
output:null
当为变量设置为 null 时,类型为 object
var a = null;
console.log(typeof a)
output:object
版权声明
本文为[十九(一拖再拖)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41974199/article/details/109630155
边栏推荐
- el-table 横向滚动条固定在可视窗口底部
- 美摄科技云剪辑,助力哔哩哔哩使用体验再升级
- 枫桥学院开元名庭酒店DMR系统解决方案
- Gather, unsqueeze and other operators when PTH is converted to onnx
- 江宁医院DMR系统解决方案
- 机器视觉系列(01)---综述
- Discussion on frame construction and technology selection of short video platform
- 启动mqbroker.cmd失败解决方法
- 自定义classloader并实现热部署-使用loadClass
- 可视化之路(十二)Collection类详解
猜你喜欢
可视化常见绘图(一)堆叠图
Jiangning hospital DMR system solution
可视化常见绘图(三)面积图
海南凤凰机场智能通信解决方案
免费开源充电桩物联网云平台
USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference
AUTOSAR从入门到精通100讲(五十二)-诊断和通信管理功能单元
AUTOSAR从入门到精通100讲(五十一)-AUTOSAR网络管理
电力行业巡检对讲通信系统
关于'enum'枚举类型以及结构体的问题。
随机推荐
PyTorch 10. Learning rate
go语言映射操作
使用compressorjs压缩图片,优化功能,压缩所有格式的图片
网络层重要知识(面试、复试、期末)
基于51单片机的温湿度监测+定时报警系统(c51源码)
SDC intelligent communication patrol management system of Nanfang investment building
可视化之路(十)分割画布函数详解
AUTOSAR从入门到精通100讲(八十四)-UDS之时间参数总结篇
AUTOSAR从入门到精通100讲(八十六)-UDS服务基础篇之2F
使用proteus仿真STM32超声波SRF04测距!Code+Proteus
Tensorflow安装后ImportError: DLL load failed: 找不到指定的模块,且国内安装缓慢
使用el-popconfirm和el-backtop不生效
x86架构初探之8086
北峰通信助力湛江市消防支队构建PDT无线通信系统
excel实战应用案例100讲(八)-Excel的报表连接功能
quill-editor图片缩放、在一个页面使用多个富文本框、quill-editor上传图片地址为服务器地址
Emergency medical communication solution | mesh wireless ad hoc network system
PyTorch 11. Regularization
AUTOSAR从入门到精通100讲(八十三)-BootLoader自我刷新
PyTorch 12. Hook usage