Utilizor
Contact Us

Basic If

The if statement.

Basic If

Use the if statement to specify a block of JavaScript code to be executed if a condition is true.

if (condition) { // block of code to be executed if the condition is true }

Note that if is in lowercase letters. Uppercase letters (If or IF) will generate a JavaScript error.

Example

if (hour < 18) {
  greeting = "Good day";
}