An if statement is a way that you can allow your computer to make a decision based on the rules you give it. Basically, you ask your computer if something is true, if so, then it will run all the code you want it to if it is true, and if not, it can a run the false-side of the code.
This may not make any sense, so lets see it applied. Let's say you have a variable "age." Let's assume
that this variable receives its value from an input field by the user. We, for some reason, want to know
if the user is old enough to drive, so we run the variable through an if statement that looks like this.
if (age < 16)
{document.write("You can't drive.");}
else
{document.write("You can probably drive.");}
A set of parenthesis follow the "if." Inside of the parenthesis are where you write what you want the if statement to check. So, in the example above, the if statement is check whether the variable "age" is less than 16 or not. If it is, it will write out on the screen "You can't drive." If it is false (if the age is actually greater than 16), then "You can probably drive." will appear on the screen.
Decision logic like this is very important to understand and is essential when it comes to coding. It is also important to note that you are not just limited to checking if something is less than something or greater than something, but you can also check if something is equal to something. To do this, just use two equal signs, like this, "if (var1 == 16)". "!=" is used for does not equal.
You can just let it be true and do something and nothing if false or you can have a path for true and a path for false. Not only that, but you can nest an if statement inside of an if statement. (do age and then license here)
If/else...and nesting..
and && (amper sand?) and or || (pipe symbols)
A switch statement tests one variable for many different outcomes. It can be used instead of having to use an exuberant amount of if statements.