If / else

Branch on conditions: parentheses required.

Conditions go in parentheses after if. The body can be a single statement or a { ... } block.

else attaches to the nearest if. Only false and nil are falsy.

if / else chain

Pick one branch with `if`, `else if`, and `else`. The condition must be in parentheses.

if / else chain
var score = 85;

if (score >= 90) {
  print "A";
} else if (score >= 80) {
  print "B";
} else {
  print "Keep going";
}
output
B

Truthy / falsy

Only `false` and `nil` skip the body. Zero and empty strings are still truthy.

Truthy / falsy
if (nil) print "no";
if (0) print "zero is truthy";
if ("") print "empty string is truthy";
output
zero is truthy
empty string is truthy