The postshows you how to use the null coalescing operator (??) instead of logical or (||) to set default values in TypeScript 3.7 to prevent expected bugs in your code.

const val = ;
const correct = (val !== undefined && val !== null) ? val : 0.5;
// const incorrect = val || 0.5; // || check all the falsy value
const incorrect = val ?? 0.5; // ?? check only null and undefined
console.log({ correct, incorrect });

最新文章

  1. Python成长笔记 - 基础篇 (七)python面向对象
  2. 开发工程师面试的秘密( 整理自 Export C Programming )
  3. CSS z-index 属性的使用方法和层级树的概念
  4. Java-->Gson序列化及反序列化
  5. ios block和函数的区别
  6. 关于eclipse中删除多余的工作空间记录
  7. 【java】利用异常机制,往前台写错误信息
  8. 修改css
  9. Spring MVC 关于分页的简单实现
  10. 【2017-03-20】HTML基础知识、文字标记、图片标记、空格换行、表格、表格嵌套及布局、超链接
  11. grub2与grub区别
  12. LOJ #6060. 「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set
  13. 解决layui table方法渲染时时间格式问题
  14. 开源中国/码云 README.md上传图片的爬坑记录
  15. Spark SQL例子
  16. C#网络编程技术FastSocket实战项目演练
  17. jmeter ---模拟发送TCP/UDP/HTTP/FTP等请求包
  18. Supervisor 进程管理工具
  19. ssh-keygen生成私钥和公钥
  20. Objective-C:异常的处理

热门文章

  1. 用Python实现扑克牌面试题思路
  2. python实战项目 — 爬取 校花网图片
  3. 44 容器(三)——ArrayList索引相关方法
  4. macbook下使用pycharm2019版本配置远程连接服务器
  5. logrus 剖析之 hook
  6. microk8s 搭建
  7. tkinter学习笔记_06
  8. Geoserver 跨域设置
  9. SpringBoot打成jar包后无法读取resources资源文件
  10. Attribute与Property关系