Enums
enum Direction {
Up,
Down,
Left,
Right
}
function doSomething(keyPressed: Direction) {
// do something.
}
doSomething(Direction.Up);console.log(Direction.Up); // Output: 0Last updated
enum Direction {
Up,
Down,
Left,
Right
}
function doSomething(keyPressed: Direction) {
// do something.
}
doSomething(Direction.Up);console.log(Direction.Up); // Output: 0Last updated
enum Direction {
Up = 1,
Down, // 2
Left, // 3
Right // 4
}
function doSomething(keyPressed: Direction) {
// do something.
}
doSomething(Direction.Down);enum Direction {
Up = "UP",
Down = "Down",
Left = "Left",
Right = "Right"
}
function doSomething(keyPressed: Direction) {
// do something.
}
doSomething(Direction.Down);enum ResponseStatus {
Success = 200,
NotFound = 404,
Error = 500
}
app.get("/", (req, res) => {
if (!req.query.userId) {
res.status(ResponseStatus.Error).json({});
}
// and so on...
res.status(ResponseStatus.Success).json({});
});