Forbes magazine logo Ranked Best Coding Bootcamps 2023

What is Conditional?

Web Development Jargons Explained in 4 Different Ways

TLDR: A conditional represents a choice in a program, it dictates what happens next. Such as, if today is a Monday, then make a reservation for dinner with the family, otherwise, eat dinner alone with TV.

Explain like I only speak in plain English

A conditional is a choice. It is a piece of program that will only happen if a condition is met. Such as, if today is a Monday, then make a reservation for dinner with the family, otherwise, eat dinner alone with TV.

Conditionals are used often in programs to dictate execution flow path. Usually, conditionals are created using if-else statements. If condition is met, do this, else, do that. You can also chain multiple if-else statements together


Explain like I'm a total nerd

Conditionals are available in almost all programming languages. Most conditionals are created using if statements. You can chain multiple if statements together and the computer will run them from top to bottom.

When one of the conditionals is satisfied, the code inside the conditional will be executed. The remaining chained conditionals will not be run.

Some programming languages also support the switch statement, which allows programmers to write more concise conditionals.

Explain like I Like Examples

The following is a chained if-else statement written in JavaScript. It will print the sentence "A good day to play hide and seek." because the weather variable is set to "foggy".

var weather = "foggy";
if (weather == "sunny") {
  console.log("I will go outside and play.");
} else if (weather == "foggy") {
  console.log("A good day to play hide and seek.");
} else {
  console.log("<a href='/explain/javascript' style='font-weight: unset;'>JavaScript</a> is more fun anyway.");

Explain like I like videos

We are trusted by

Students and instructors from world-class organizations

Imperial College London
Carnegie Mellon University
City University of Hong Kong
Hack Reactor
Cisco Meraki
University of Oxford
Boston College
Bombardier Aerospace
University of St. Andrews
New York University
Minerva Schools at KGI
Merrill Lynch
Riot Games
JP Morgan
Morgan Stanley
Advanced Placement®
The University of Hong Kong
University of Toronto
Hello Toby
Goldman Sachs
General Assembly
McGill University

Join the upcoming Cohort #91

Enroll for July 1st, 2024