A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/statements/if_else below:

if else ยท WebPlatform Docs

if else Summary

Conditionally executes a group of statements, depending on the value of an expression.

Syntax
if ( condition1 ) {
     statement1
} else if ( condition2 ) {
     statement2
} else {
     statement3
}
condition1
Required. A Boolean expression. If condition1 is null or undefined , condition1 is treated as false.
statement1
Optional. The statement to be executed if condition1 is true. Can be a compound statement.
condition2
The condition to be evaluated.
statement2
Optional. The statement to be executed if condition2 is true. Can be a compound statement.
statement3
If both condition1 and condition2 are false , this statement is executed.
Examples

The following code shows how to use if , if else , and else.

It is good practice to enclose statement1 and statement2 in braces ({}) for clarity and to avoid inadvertent errors.

var z = 3;
 if (x == 5) {
     z = 10;
 }
 else if (x == 10) {
     z = 15;
 }
 else {
     z = 20;
 }
See also Other articles Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4