Branching with if and else in TypeScript is straightforward.
To run this TypeScript code, you would typically compile it to JavaScript and then run it with Node.js:
Note that you do need parentheses around conditions in TypeScript, and the braces are required for multi-line blocks but optional for single-line statements.
TypeScript (and JavaScript) do have a ternary operator (?:), which can be used for simple conditional expressions:
This can be useful for assigning values based on a condition, but for more complex logic, full if/else statements are often clearer.