The if statement lets you execute a block of code if some test is passed.
var x=5; if(x==5){ alert('x is equal to 5!'); }
You can also use an else clause to execute code if the test fails.
var x=5; if(x==5){ alert('x is equal to 5!'); }else{ alert('x is not equal to 5!'); }
An elseif statement also exists which allows for better formating of
long conditional tests.
var x=5; if(x==1){ alert('x is equal to 1!'); }elseif(x==2){ alert('x is equal to 2!'); }elseif(x==5){ alert('x is equal to 5!'); }else{ alert('x isn't 1,2or5!'); }