Introduction to if-statements

Learn one of the building blocks of programming, the if-statement. Learn how to run code conditionally. Learn what truthy and falsey mean in JavaScript.

We can now get to something you’ll use throughout your career in every programming language you’ll ever touch: if-statements.

if-statements

They’re meant to run a piece of code if a certain condition is true. If it’s false, it’ll skip the code and move on.

An if-statement is written in this format:

if(/*condition*/) {
    // conditional code
}

Here’s an example.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy