Skip to guide content
[js] recap
Chapter 1 · Fundamentals Conditional statements (if / else)

1.6

Conditional statements (if / else)

Examples with a Run button are editable. Underlined terms open a short definition.

Conditional Statment ( if-Else )

const age = 19;
if (age >= 18) {
    // logical condition
    status = 'Eligible for driving License.'; // executed if condition is true
} else {
    // else block is optional
    const yearsLeft = 18 - age;
    status = `Not eligible for driving License. Wait for ${yearsLeft} years`;
    // executed if condition is false
}

Your last opened chapter is saved in this browser when local storage is available.

Discuss this section

Questions, corrections or a better example? Comments use GitHub Discussions.