Tuesday, November 1, 2016

Javascript If Else Statements and Switch Reflection Journal


       I learned about the selection statements which were the if else and switch statements. The if statement executes a code if the condition is true. In the if else statement the else statement is executed if the condition in the if statement is not true. The else if statement has a different condition from the if statement and executes the code in the else if statement when the condition from the if statement is not true and the condition in the else if statement is true. The else statement executes the code if both the if statement and else if statement conditions are false. The switch statement has many different possibilities and can execute the code according to the case. The difference between the if else statements and the switch statements are that the code from the if else statements stops at 3 statements at the max while you can have as many cases as you want for the switch statement. The switch statement also has a default in case if none of the cases are applied. You have to be careful when writing your code because it is case sensitive so you have to make sure that it is written exactly as it should be like for these statements in all lowercase. The default for the switch statement does not necessarily have to be the last case in the switch statement, though it is preferred. Also the break in the switch statement tells the computer to stop testing the case after it gets the match and saves a lot of time.

No comments:

Post a Comment