Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Using if Statement | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Essential TypeScript Basics for JavaScript Developers - 1768407373799

bookUsing if Statement

It's our turn to control the code; now we will set conditions for its execution!

Let's consider the most basic form of conditional statements - the if statement.

Let's move on to the syntax:

if (condition) {
	// code to be executed if the condition is true
}

For example:

12345
let amIHappy = true; if (amIHappy) { console.log('I am so happy!'); } console.log("It's Monday");
copy

That's almost all there is to it, but there's one more thing worth mentioning. Inside the condition block, there should be a boolean value. However, we can also place an expression that will result in a boolean value inside this block, for example:

1234
let age: number = 22; if (age >= 21) { console.log('You can buy alcohol'); }
copy

You can change the value of the variable age to see how the code works depending on that value.

I'll tell you how to set a condition if the first one doesn't work in the next chapter!

question mark

What will be the result of executing this code?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 9

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookUsing if Statement

Swipe um das Menü anzuzeigen

It's our turn to control the code; now we will set conditions for its execution!

Let's consider the most basic form of conditional statements - the if statement.

Let's move on to the syntax:

if (condition) {
	// code to be executed if the condition is true
}

For example:

12345
let amIHappy = true; if (amIHappy) { console.log('I am so happy!'); } console.log("It's Monday");
copy

That's almost all there is to it, but there's one more thing worth mentioning. Inside the condition block, there should be a boolean value. However, we can also place an expression that will result in a boolean value inside this block, for example:

1234
let age: number = 22; if (age >= 21) { console.log('You can buy alcohol'); }
copy

You can change the value of the variable age to see how the code works depending on that value.

I'll tell you how to set a condition if the first one doesn't work in the next chapter!

question mark

What will be the result of executing this code?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 9
some-alt