If statements

An if statement executes a block of instructions if the given condition is true. A block is a group of instructions in curly braces ({ and }), and a condition is any true or false value.

if statement
if (condition) { ... }

Consider the simple program below, which only performs the console.log instruction if the value in score is greater than 80.

Loading TypeScript...

Recall from the basics that JavaScript considers empty strings and zero to be false values, and non-empty strings/non-zero values to be true values.

Loading TypeScript...

Was this page helpful?