Conditional Statements

Conditional Statements: Making Decisions

Conditional statements let your code make decisions, just like you decide what to wear based on the weather. They check if something is true or false and then do different things based on the result.

if Statement – The Basic Decision

Copy to Clipboard

if…else Statement – Two Choices

Copy to Clipboard

if…else if…else Statement – Multiple Choices

Copy to Clipboard

Truthy and Falsy Values

JavaScript treats some values as true and others as false:

Copy to Clipboard

Tip: Use meaningful variable names and clear conditions to make your code readable!