当前位置:网站首页>基础类型变量声明
基础类型变量声明
2022-06-29 10:47:00 【豆瓣酱,】
一,前言
1.相对于javascript,typescript的一个特点是可以声明具有数据类型的变量。
2.当对已经确认数据类型的变量赋值不同类型的值时,会在编译时报错,某种程度上可以将typescript理解成强类型的javascript
二,声明形式
1.let [变量名] : [类型] = 值 或者 let [变量名] : [类型]
let a:number = 10
let b:string
2.声明变量的类型,但没有初始值,变量值会设置为 undefined
三,合法的基础类型
1.任意类型:any
let a:any = 'hello world'
a = 123 //赋值为不同的类型不会报错
2.数字类型:number
let a:number = 123
let b:number = 0b1010
3.字符串类型:string
let a:string = "123"
4.布尔类型:boolean
let a:boolean = true
5.数组类型:[类型][] || Array<类型>
let a:any[] = [1,"2",true]
let b:Array<number> = [1, 2, 3]
6.对象类型:object
let a:object = [1,"2",true]
let b:object = {
a:1}
7.null和undefined,在ts中,undefined和null两者各自有自己的类型分别叫做undefined和null,本身用处不大
let a:undefined = undefined
let b:null = null
8.元组
9.枚举
10.void
边栏推荐
- (JS) imitate the indexof method to find the position of a character in the string
- Pipeline aggregations管道聚合- parent-2
- 专访 SUSS NiFT 负责人:Web3 的未来离不开“人人为我,我为人人”的治理
- Oracle扩充分布式云端服务 为更多客户带来全面公有云服务
- 深入理解 volatile 关键字
- 毕业5年,我问遍了身边的大佬,总结了他们的学习方法
- Opencv4.0 installation of raspberry pie for Xiaobai
- What are the main factors that affect the heat dissipation of LED packaging?
- What is the experience of working in an IT company in Japan?
- 【高并发】缓存思路
猜你喜欢

The first "cyborg" in the world died, and he only transformed himself to "change his life against the sky"

Exclusive interview with CTO: the company has deepened the product layout and accelerated the technological innovation of domestic EDA

QT learning 09 calculator interface code reconstruction

Qt学习07 Qt中的坐标系统

Today in history: musk was born; Microsoft launches office 365; The inventor of Chua's circuit was born

Modbustcp protocol network learning single channel infrared module (medium shell version)

Bs-gx-018 student examination system based on SSM

XML外部实体注入漏洞(一)

信息技术应用创新专业人员(数据库)中级培训火热招生中(7月6-10日)

Nature | biosynthetic potential of global marine microbiome
随机推荐
记一次 MSI 笔记本 GE63 播放网页视频 闪屏和随机发绿 问题解决
(JS) iterator mode
基于集群的动态反馈负载均衡策略
MySQL开启慢查询
Qt学习15 用户界面与业务逻辑的分离
又拍云 Redis 的改进之路
ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)
Xuetong denies that the theft of QQ number is related to it: it has been reported; IPhone 14 is ready for mass production: four models are launched simultaneously; Simple and elegant software has long
(JS) imitate an instanceof method
Qt学习04 Hello Qt
XML外部实体注入漏洞(一)
【每日3题(3)】重新格式化电话号码
Self-Improvement! Junior college "counter attack" master of Zhejiang University, 3 SCI, and finally become a doctor of Tsinghua University!
【高并发】2.8万字的Callable和Future面试知识点总结,看完我直接面进了字节跳动,原谅我有点飘了(上)
X-FRAME-OPTIONS web page hijacking vulnerability
Oracle扩充分布式云端服务 为更多客户带来全面公有云服务
中国计算语言学大会、全国知识图谱与语义计算大会赛题火热进行中
CICD简介[通俗易懂]
基于鲲鹏开发套件实现x86平台到Kunpeng平台的源码迁移【玩转华为云】
Week 12 experiment -- implementation of VGA protocol based on FPGA