Enumerations

JavaScript Enumerations


link - typescriptlang.org/docs/handbook/enums.html


Numerical Enumerations

The default starting number for enumerations is 0.

enum myEnum = { 
   Up = 0,
   Down = 1,
   Right = 2,
   Left = 3
}

let myValue: number = myEnum.Up;



enum myEnum = { 
   Up = 100,
   Down = 200,
   Right = 300,
   Left = 400
}

String Enumerations


enum myEnum = { 
   Up : 'Up string',
   Down : 'Down string',
   Right : 'Right string',
   Left : 'Left string'
}

let myValue: number = myEnum.Up;


const enum

Never do this because it changes it completely
you cannot us the strings in code
good if you are doing only comparison




© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext