- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Eric Pimpler Mark Lewin
- 137字
- 2021-07-02 15:48:54
Decision support statements
An if/else statement in JavaScript and other programming languages is a control statement that allows for decision-making in your code. This type of statement performs a test based on an expression, that you specify at the top of the statement. If the test returns a value of true then the statements associated with the if block will run. If the test returns a value of false then the execution skips to the first else if block. This pattern continues until a value of true is returned in the test or the execution reaches the else statement. The following code example shows how this statement works:
var layerName = 'streets'; if (layerName == 'aerial') { alert("An aerial map"); } else if (layerName == "hybrid") { alert("A hybrid map"); } else { alert("A street map"); }