Else
There is also an else
clause that will be applied when the first condition isn’t true. This is very powerful if you want to react to any value, but single out one in particular for special treatment:
let umbrellaMandatory;
if (country === "England") {
umbrellaMandatory = true;
} else {
umbrellaMandatory = false;
}
The else
clause can be joined with another if
. Let's remake the example from the previous article:
if (country === "England") {
...
} else if (country === "France") {
...
} else if (country === "Germany") {
...
}
Last updated
Was this helpful?