Conditional statements are used in JavaScript to perform distinct actions based on a set of conditions and determines whether a code can run. If the condition is true the code can run, and if it is false it cannot run. if / else is the most common conditional statement in JS. A condition is enclosed in the parentheses after the if statement, and the resulting output is enclosed in curly brackets. The code tests to see if the condition is true. If there are multiple conditions, they can be declared using else if (different condition). The output will run for the condition that tests true. If all conditions test false, then the output for else {} will run.
example:
if (condition) {
var output = “output”;
} else if (different condition) {
var output = “output2”;
} else if (different condition) {
var output = “output3”;
} else {
var output = “output4”;
}
Hey, Catrina. I want to thank you for making me aware and helping me understand what conditional statements are in JavaScript. I like how you’re straight to the point.