if/else
Same concept as Python, different syntax:- JavaScript
- Python
else if instead of elif.
Conditions must be in parentheses
Truthy and falsy values
JavaScript evaluates any value astrue or false in a condition. This matters more than you’d expect.
Falsy values (evaluate to false):
Practical use of truthy/falsy
Ternary operator
A one-line if/else. You’ll use this constantly in React for conditional rendering.condition ? valueIfTrue : valueIfFalse
Ternary in React
This is where the ternary operator really shines:Logical operators
&& (AND) — short-circuit rendering
Returns the second value if the first is truthy. Otherwise returns the first.&& is the most common way to conditionally show something:
|| (OR) — fallback values
Returns the first truthy value.?? (nullish coalescing) — null/undefined fallback
Returns the right side only if the left isnull or undefined. Doesn’t trigger on 0, "", or false.
switch statements
For multiple conditions against the same value:What’s next?
You can make decisions with conditionals. Now let’s learn how to repeat actions with loops.Loops
Iterate over data with for loops and more