The if/else statements are considered to be part of Javascripts conditional statements. They are used to perform different actions based on different conditions When using if/else in Javascript, the code is examining if a specific condition is true. If the condition ends up being false, you can prescribe another block of code. You use “If” in Javascript if the statement is true. The code will work if that condition is true. You use “else” in Javascript when the statement is false and you use ” else if” to specify a new condition to test if the first condition is false (w3school.com). The syntax of the if statement is if (condition) { // block of code to be executed if the condition is true } ]. The syntax of the else statement is if (condition) { // block of code to be executed if the condition is true} else { // block of code to be executed if the condition is false }. Finally, the syntax for the else is statement is if (condition1) { // block of code to be executed if condition1 is true else if (condition2) { // block of code to be executed if the condition1 is false and condition2 is true} else { // block of code to be executed if the condition1 is false and condition2 is false.
Javascript if…else. JavaScript if/else Statement. (n.d.). Retrieved March 2, 2023, from https://www.w3schools.com/jsref/jsref_if.asp#:~:text=The%20if%2Felse%20statement%20executes,actions%20based%20on%20different%20conditions.