Introduction and Topic Overview

Welcome to our new JavaScript adventure. Today, we're exploring the world of conditional statements. Just as decisions are made in real life, conditional statements in JavaScript guide a program in determining which steps to take under certain conditions.

In this lesson, we're going to explore:

  • The basic if statement — the pathway for making single-pathway decisions.
  • else and else if statements — options for making multi-pathway decisions.
  • Compound conditionals — an alternative for managing complex decisions involving multiple conditions.
  • The Ternary Operator — a shorthand method for making swift, simple decisions.
Understanding Conditional Statements - The Basic 'If' Statement

Our journey begins with the straightforward if statement, which checks a specific condition and takes action if the condition is true. Similar to determining whether an apple is ripe enough to eat, the if statement would appear like this :

Here, the if-condition checks the condition (apple === 'ripe'), and if it is true, it performs the action inside the { ... } block, which is a statement here.

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