Alternatives with "else " and "else if"
The if...else is a type of conditional statement that will execute a block of code when the condition in the if statement is truthy. If the condition is false, then the else block will be executed.
Truthy and falsy values are converted to true or false in if statements.
if (condition is true) {
// code is executed
} else {
// code is executed
}
Any value that is not defined as falsy would be considered truthy in JavaScript.
Here is a list of falsy values:
false
0 (zero)
-0 (negative zero)
0n (BigInt zero)
"", '', `` (empty string)
null
undefined
NaN (not a number)
Comments
Post a Comment