Welcome to our TypeScript undertaking. Today, we are examining the concept of conditional statements. Much like life, TypeScript's conditional statements guide the program based on various conditions.
In today's lesson, we'll cover:
- The basic
if
statement — the pathway for making single-pathway decisions. else
andelse if
statements — options for making multiple decision paths.- Compound conditionals — workarounds for handling complex decisions involving multiple conditions.
- The Ternary Operator — a shorthand method for making quick, straightforward decisions.
Our exploration starts with the basic if
statement, which validates a particular condition and performs an action if the condition is fulfilled. To illustrate, imagine deciding whether a watermelon is ready to eat, here's what the if
statement would look like :
In the above code, the condition watermelon === 'ready'
is evaluated. If it is true, the action inside the { ... }
block is executed, which is in this case.
