web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

typescript参数名后面的问号是什么意思?

322 ℃
     

举例说明

function getval(x: number, y?: number) {
  return x + (y || 0);
}
getval(1, 2);
getval(1);
getval(1, undefined);
getval(1, null); // error, 'null' is not assignable to 'number | undefined'

?? 和 || 的意思有点相似,但是又有点区别。 ?? 表示当值为undefined或者null时,就会取后面的值; || 表示当前面的值为假值是 则去后面的值

console.log(null || 5)   //5
console.log(null ?? 5)     //5
console.log(undefined || 5)      //5
console.log(undefined ?? 5)      //5
console.log(0 || 5)       //5
console.log(0 ?? 5)      //0

?.的意思基本和 && 是一样的

a?.b 相当于 a && a.b ? a.b : undefined
const a = {
  b: { c: 7 }
};
console.log(a?.b?.c);     //7
console.log(a && a.b && a.b.c);    //7

vue3相对于vue2有哪些新特性?

TypeScript语法中有哪些操作符?

typescript语法中is关键字是做什么的?

简单介绍一下什么是TS的应用(vue开发)

标签: typescript

上面是“typescript参数名后面的问号是什么意思?”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_12056.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计487个字,预计阅读时长4分钟
生活小工具,收录了80多款小工具
上一篇: 推荐2款充满科技感的艺术字体——小新黑体、小新潮酷体
下一篇: 推荐一款浏览器数据库的开源工具库——Dexie.js(JavaScript调用)
x 打工人ai神器