Concepts·5 / 9

Decisions with if / else

~6 min read

An if-statement lets your program pick between paths.

let temperature = 22;

if (temperature > 30) {
  console.log('Wear shorts.');
} else if (temperature > 15) {
  console.log('Light jacket.');
} else {
  console.log('Bundle up!');
}
Interactive · code playground
Code
Output

Made with Emergent