Conditional Expressions and Optional Chaining
Learn what conditional expressions are and how we can use nested properties through optional chaining.
We'll cover the following
Conditional expressions
Conditional expressions, also known as ternary expressions, are a feature of JavaScript that allows us to write concise statements that execute different actions depending on a boolean condition. They have the following syntax:
(conditional) ? ( true statement ) : ( false statement );
We can use this JavaScript feature in TypeScript language, which uses a question mark ( ?
) symbol to define the if
statement and a colon ( :
) to
define the then and else paths.
As an example of this syntax, consider the following code:
Get hands-on with 1400+ tech skills courses.