CKTIS / JavaScript
else — the alternative branch of an if statement
The `else` keyword introduces the branch executed when the associated `if` condition converts to `false`. It is optional and cannot appear on its own.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
if (condition) {
statementA;
} else {
statementB;
}else is a reserved JavaScript keyword that introduces the alternative branch of an if statement. The condition is evaluated and converted to a Boolean: true selects the first branch, and false selects the else branch. The unselected branch is not executed.
else has no condition of its own. Writing else if (...) places another if statement inside the else branch; it is not a separate keyword. An if can appear without else; an isolated else is a syntax error.
Each branch contains one statement, which can be a block { ... }. Use blocks to make grouping explicit: without them, else binds to the nearest inner if that does not already have an else, regardless of indentation.
In the example, score >= 50 evaluates to false, so result receives "retry". The expected output is one line: retry.
Examples
const score = 42;
let result;
if (score >= 50) {
result = "pass";
} else {
result = "retry";
}
console.log(result);Result
retry
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.