Jul 21, 2024
if-else
Statementsif-else
: Fundamental structure for making decisions in JavaScript.num1
and num2
.num1 > num2
to get a boolean result.if
statement to print if num1
is greater.else
statement to handle the case where num2
is greater.let num1 = 6;
let num2 = 4;
if (num1 > num2) {
console.log("num1 is greater");
} else {
console.log("num2 is greater");
}
console.log("Bye");
if
or else
using {}
curly brackets.if (num1 > num2) {
console.log("num1 is greater");
console.log("Yay");
} else {
console.log("num2 is greater");
}
&&
, ||
) to combine multiple conditions.num1
, num2
, num3
).let num1 = 8;
let num2 = 6;
let num3 = 7;
if (num1 > num2 && num1 > num3) {
console.log("num1 is greatest");
} else if (num2 > num1 && num2 > num3) {
console.log("num2 is greatest");
} else {
console.log("num3 is greatest");
}
if-else
to determine if a given number is even or odd.if
, else
, else if
are crucial for control flow in JavaScript.End of Lecture