Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Complex Conditions | Conditional Statements
Introduction to TypeScript

Complex ConditionsComplex Conditions

While contemplating how to further complicate the if statement, specifically the condition block, thanks to the benevolent developers of TypeScript and JavaScript, you can now use multiple conditions in a single block.

For example, you need to set two conditions: the number must be greater than 0 AND less than 99. (For instance, you're a seller of LEGO sets)

As you can see, we've set a double condition. We need the age to be greater than 0 AND less than 99. To achieve this, we used symbols like &&. There's another option, which is when we need to set multiple conditions, and any of them can be satisfied. In simpler terms - OR. Let's take a look at an example:

As you can see, we used || to set the OR condition. In our code above, if the grade is Very well or Good, then we've done our job well. Let's quickly remember these keywords:

  1. AND = &&;
  2. OR = ||.
  • true && false = false;
  • true && true = true;
  • false && false = false;
  • true || true = true;
  • true || false = true;
  • false || false = false.

By the way, you can use multiple such conditions simultaneously. For example, you may need 3 or 4 of them. For instance, if we need to retrieve a number between 20 and 50 OR between 70 and 100:

We can group conditions in parentheses, just like in mathematics. This means that conditions within the parentheses will be checked first, and then conditions outside the parentheses will be evaluated.

What will be the result of executing this code?

Select the correct answer

Everything was clear?

Section 2. Chapter 5
course content

Course Content

Introduction to TypeScript

Complex ConditionsComplex Conditions

While contemplating how to further complicate the if statement, specifically the condition block, thanks to the benevolent developers of TypeScript and JavaScript, you can now use multiple conditions in a single block.

For example, you need to set two conditions: the number must be greater than 0 AND less than 99. (For instance, you're a seller of LEGO sets)

As you can see, we've set a double condition. We need the age to be greater than 0 AND less than 99. To achieve this, we used symbols like &&. There's another option, which is when we need to set multiple conditions, and any of them can be satisfied. In simpler terms - OR. Let's take a look at an example:

As you can see, we used || to set the OR condition. In our code above, if the grade is Very well or Good, then we've done our job well. Let's quickly remember these keywords:

  1. AND = &&;
  2. OR = ||.
  • true && false = false;
  • true && true = true;
  • false && false = false;
  • true || true = true;
  • true || false = true;
  • false || false = false.

By the way, you can use multiple such conditions simultaneously. For example, you may need 3 or 4 of them. For instance, if we need to retrieve a number between 20 and 50 OR between 70 and 100:

We can group conditions in parentheses, just like in mathematics. This means that conditions within the parentheses will be checked first, and then conditions outside the parentheses will be evaluated.

What will be the result of executing this code?

Select the correct answer

Everything was clear?

Section 2. Chapter 5
some-alt