Skip to content
dreamcode
dreamcode
Map
If & Else
Lesson 7 of 48
+15 XP on finish
JAVASCRIPT CLIMBSChapter 2 · JS Conditionals & Logic

JavaScript If & Else

An if statement evaluates a condition in parentheses. If True, it executes the block in curly braces. An optional else block runs if the condition is False.

Worked example

How it reads

  • if (isRainy) checks if the condition inside parentheses is true
  • Curly braces {} group the statements to execute for each branch
Cloud tip: Unlike Python, JavaScript does not rely on indentation to find blocks; it uses curly braces. But keep your code indented for readability.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Change only the value of temp so the program takes the first branch and logs Cold.

Press Run to check your work.