当前位置:网站首页>Simple use of enum type in TS
Simple use of enum type in TS
2022-06-26 06:23:00 【One at the front】
Why enumerate ?
Enumeration is just TypeScript A useful way to organize code in . Here are some reasons why enumeration comes in handy :
- Use enumeration , You can create constants that are easy to associate , Make constants clearer
- Developers are free to JavaScript Create memory efficient custom constants in . As we know ,JavaScript Enumeration is not supported , but TypeScript Can help us access them
- TypeScript Use enumerated JavaScript Inline code in saves running time and compilation time
- TypeScript Enumeration also provides that we used to have only in Java And other languages . This flexibility allows us to easily express and document our intentions and use cases
// The default from the 0 Start
enum Direction{
Up,
Down,
Left,
Right,
}
console.log(Direction.Up)//0
console.log(Direction[0])//up
// After assignment, and so on
enum Direction2{
Up=1,
Down,
Left,
Right,
}
console.log(Direction2.Down)//2
console.log(Direction2[2])//Down
// Assignment string
enum Direction3{
Up='UP',
Down='DOWN',
Left='LEFT',
Right='RIGHT',
}
const value='UP'
if(value==Direction3.Up){
console.log('go up');
}边栏推荐
- 消息队列-功能、性能、运维对比
- 稀疏数组sparsearray
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
- Laravel implements groupby to query the number of packets
- 低代码实时数仓构建系统的设计与实践
- Efk Upgrade to clickhouse log Storage Reality
- Library management system
- 实时数仓方案如何选型和构建
- PyTorch混合精度原理及如何开启该方法
- 温度报警器
猜你喜欢
随机推荐
Message queue - function, performance, operation and maintenance comparison
Message queuing - omnidirectional comparison
Efk upgrade to Clickhouse log storage practice
Hot! 11 popular open source Devops tools in 2021!
PyTorch使用多GPU并行训练及其原理和注意事项
How to design a good technical scheme
Comparison between Prometheus and ZABBIX
Static proxy mode
GoF23—原型模式
Requirement analysis of personal blog system
GoF23—工厂模式
Understanding of nil in go language
Redis multithreading and ACL
Mongodb -- use mongodb to intercept the string content in the field and perform grouping statistics
打印数字的位信息
成水最多的容器
A new paradigm for large model application: unified feature representation optimization (UFO)
个人博客系统需求分析
LightGBM--调参笔记
Zotero文献管理工具之Jasminum(茉莉花)插件









