Making Decisions with Conditionals: An Overview

Greetings, coding explorer!

Today, we're diving into conditional statements, a key principle in programming. Conditionals, like day-to-day decisions, are dictated by circumstances. For instance, should it rain, you'd opt for an umbrella. Code operates in a similar manner. They control the flow of code, mobilizing actions based on whether conditions are true or false. We'll be exploring this concept today.

The "if" Statement: Initiating Decision-Making

Regard the if statement as the gatekeeper of conditionals. It definitively states, "If this is true, then perform this specific action". It’s comparable to choosing between chocolate and vanilla ice cream. Let’s take a closer look at an example:

Note that in JavaScript, the conditions we inspect using if statement must always be wrapped in parentheses, like so: if (condition). The if statement applies to all statements within its block formed by braces ({}).

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal