Find more freelance jobs
|
In JavaScript we have two conditional statements:
·
if...else statement - use this statement if you want to select one of two sets of lines to execute
·
switch statement - use this statement if you want to select one of many sets of lines to execute
If Condition
You should use the this statement if you want to execute some code if a condition is true, or if you want to select one of two blocks of code to execute. If you want to execute only one statement when a condition is true, use this syntax for the if...else statement, like this: if (condition) { code to be executed if condition is true } Notice that there is no ..else.. in this syntax. You just tell the code to perform one action if the condition is true. If you want to execute some statements if a condition is true and execute others if a condition is false, use this syntax for the if....else statement, like this: if (condition) { code to be executed if condition is true } else { code to be executed if condition is false } Equality Operators Operator Meaning == is equal to != is not equal to > is greater than >= is greater than or equal to < is less than <= is less than or equal to Switch Condition You should use the this statement if you want to select one of many blocks of code to execute. switch (expression) |