Ternary Statements & Dictionaries
Learn to use ternary statements and dictionaries in Python with Transcrypt.
We'll cover the following...
Ternary statements
With functional programming like we are doing with React, it’s convenient to create inline logical branching expressions for the simple True/False
type of conditions. JavaScript has a ternary operator that does just that. It takes a boolean expression that will either evaluate to True
or False
, followed by a question mark ?
. It will return a value if the expression is True
, and return another value if the expression evaluates to False
, separated by a colon :
. In our example, there is a ternary expression that determines what text shows up in the UI based on the value of editTask
:
{this.state.editTask ? "Edit Task: " : "Add
...