What are conditionals?
A conditional regulates behavior and decides whether or not certain bits of code can be executed.
Types of conditionals
Examples
if
statements
if (12 < 5) {
console.log(true);
}
else
statements
if (12 < 5) {
console.log(true);
} else {
console.log(false);
}
else if
statements
if (12 < 5) {
console.log(true);
} else if (12 > 5) {
console.log(false);
} else {
console.log(null);
}
Conditional operators
What are logical operators?
Logical statements employ logical operators to assess the equality or disparity of variables or values.
Types of logical operators
Examples
and
statements
(x < 10 && y > 1)
or
statements
(x == 5 || y == 5)
not
statements
!(x == y)
Summary
A conditional regulates behavior and decides whether or not certain bits of code can be executed. There are three types of conditionals: if
, else
and else if
. There are different conditional operators used in JavaScript, too.
A logical operator use logical statements to assess the equality of variables or values. There are 3 logical operators in Javascript: and
, or
an not
.
At first, these may be a little complicatedto master, but with practice, you will have a better understanding of it.
References