Conditions

Conditions in JavaScript run code based on an expression: if, else if, else, switch for several cases, and the ternary operator condition ? a : b to choose a value. The expression is evaluated as true or false according to the truthy/falsy rules.

Example

const statut = age >= 18 ? 'adult' : 'minor'

Related concepts

The whole glossary