Conditionals Recap
In this chapter, we learned how our program can decide what to do using conditions. We found that:
- The
if
statement executes the following block of code if its condition is true. - An
else if
statement can follow anif
statement, with an additional condition that executes the block of code of theelse if
statement if true. - An
else
statement can follow anif
orelse if
statement. The block of code of theelse
statement executes if all previous conditions are false. - After the first true condition, the corresponding block of code is executed and the rest of the conditional chain is skipped.
- Comparisons are made using the following operators:
===
- Equal to,!==
- Not equal to,>
- Greater than,>=
- Greater than or equal to,<
- Less than,<=
- Less than or equal to. - We indent the block of code following a
{
for easier readability in the code. - There are two boolean values:
true
andfalse
. - Using logical operators
&&
(and),||
(or), we can combine multiple conditions. - Using the
!
(negation) operator, we can invert a condition fromtrue
tofalse
or fromfalse
totrue
. - Nested conditions are those within the block of code of another condition.
Congratulations on completing the second lesson of JavaScript! In the next lesson, we will dive into the world of arrays and explore their amazing capabilities in programming. Get ready for an adventure full of efficient data storage and manipulation!
Instructions
When you are ready, proceed to the next lesson!
Start programming for free
9/9