当前位置:网站首页>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');
}边栏推荐
- Handwritten background management framework template (I)
- Logstash——Logstash向Email发送告警邮件
- Evolution history of qunar Bi platform construction
- TCP连接与断开,状态迁移图详解
- 工作积累——Web请求中使用ThreadLocal遇见的问题
- Multi thread synchronous downloading of network pictures
- 浏览器的四大内核:Trident,Gecko,Webkit,Blink
- Import export simple
- Deeply uncover Ali (ant financial) technical interview process with preliminary preparation and learning direction
- 技术能力的思考和总结
猜你喜欢

STM 32 使用cube 生成TIM触发ADC并通过DMA传输的问题

同步通信和异步通信的区别以及优缺点
The sysdig 2022 cloud native security and usage report found that more than 75% of the running containers have serious vulnerabilities

宝塔服务器搭建及数据库远程连接

技术能力的思考和总结
Alarm operation and Maintenance Center | build an efficient and accurate alarm collaborative processing system

MYSQL索引不生效的原因

低代码实时数仓构建系统的设计与实践

Architecture design method

消息队列-消息事务管理对比
随机推荐
如何设计好的技术方案
Gof23 - prototype mode
跨域的五种解决方案
typescript的type
自顶向下的变成方法
volatile应用场景
Tortoise and rabbit race example
Zotero文献管理工具之Jasminum(茉莉花)插件
Logstash - logstash sends an alarm email to email
Logstash——Logstash向Email发送告警邮件
3.pyinstaller模块介绍
Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
How to design a good technical scheme
架构设计方法
Pychart cannot run designer Exe (this application failed to start because no Qt platform plugin could be I appears)
Static proxy mode
事务与消息语义
Self attention and multi head self attention (MSA) in transformer
GoF23—建造者模式
Gof23 - abstract factory pattern