Created
May 9, 2019 03:57
-
-
Save hoangtranson/b97ba4bc14d12c64f936c225c2f2e6cf to your computer and use it in GitHub Desktop.
Number Enums and Strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Tristate; | |
(function (Tristate) { | |
Tristate[Tristate["False"] = 0] = "False"; | |
Tristate[Tristate["True"] = 1] = "True"; | |
Tristate[Tristate["Unknown"] = 2] = "Unknown"; | |
})(Tristate || (Tristate = {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Tristate { | |
False, | |
True, | |
Unknown | |
} | |
console.log(Tristate[0]); // "False" | |
console.log(Tristate["False"]); // 0 | |
console.log(Tristate[Tristate.False]); // "False" because `Tristate.False == 0` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So when I type
Tristate
this will return{0: "False", 1: "True", 2: "Unknown", False: 0, True: 1, Unknown: 2}