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

map.jpg

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
Swift
Bazaarvoice
Waterloo
Uber
AtlanTech
Tumblr
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®
Google
KPMG
The University of Hong Kong
University of Toronto
SCMP
Moat
Zynga
Hello Toby
Deloitte
Goldman Sachs
Yahoo
HSBC
General Assembly
Tesla
McGill University
Microsoft

Join the upcoming Cohort #96

Enroll for December 2nd, 2024