if...else Statements

If a logical condition is true, the if statement performs one or more actions. If a logical condition is false, the else clause, which is optional, performs one or more actions.

A typical if statement:

if (condition) {
  statements1 
}
else {
  statements2 
}

Conditions are JavaScript expressions that evaluate to true or false. Statements to be executed are JavaScript statements, including nested if statements. If you want to use multiple statements after an if or else statement, enclose the statements in braces {}.

Do not confuse primitive-Boolean true and false values with Boolean-object true and false values. Objects whose values are not undefined or null, including Boolean objects whose values are false, evaluate to true when passed to conditional statements, for example:

var b = new Boolean(false);
if (b) // this condition evaluates to true

Note:

If you use an initial capital letter for if or else or type the word then, you receive an error message. A then statement is implied for values enclosed in braces { }.

You can use an if...else statement to stop a script when the script encounters a selected condition, for example:

if(cellvalue==0){ Alert("Cell has no value") }
else{ (execute remainder of code here) }