: R.Allen Wyke, Jason D. Gilliam and Charlton Ting, Publisher : Techmedia . Computer Application Text Book – Govt. of Kerala Chapter Pages Learning Objectives: • To learn about control structures • To learn about logical operators in JavaScript • To learn about loops and their types • To acquire knowledge of developing JavaScript programs.
. Conditional Statements in JavaScript: Statements are executed in the order they are found in a script. Conditional statements execute or skip one or set of statements depending on the value of a specified conditional expression. There are two types of controls, • Branching / Selection • Looping / repetitive .
. Branching Statements: JavaScript supports branching statements which are used to perform different actions based on different conditions. Branching is a transfer of control from the current statement to another statement or construct in the program unit. A branch alters the execution sequence.
There are different branching statements. They are, • if statement • if … else statement • else if statement • switch statement . . .
if and if..else Statement: The if statement is the fundamental control statement that allows JavaScript to make decisions to execute statements conditionally. This statement has two forms. The form is for only true condition. The syntax is if (condition) { True block; } In the if form, condition contains relational/logical expression is evaluated.
If the resulting value is true the true block is executed. True block may contain one or more than one statement. For example