Ternary Statements & Dictionaries
Explore how to implement ternary statements for inline conditional logic and manage Python dictionaries in front-end coding using Transcrypt. Understand key differences between Python and JavaScript objects, including how Transcrypt converts dictionaries and how to handle JavaScript objects that behave like dictionaries in Python.
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 ...