1If - Else Statements
2if (condition) {
3// what to do if condition is met
4} else {
5// what to do if condition is not met
6}
7
1if (condition1) {
2 // block of code to be executed if condition1 is true
3 }
4else if (condition2) {
5 // block of code to be executed if the condition1 is false and
6 // condition2 is true
7} else {
8 // block of code to be executed if the condition1 is false and
9 // condition2 is false
10 }
1if (expression) {
2 Statement(s) to be executed if expression is true
3} else {
4 Statement(s) to be executed if expression is false
5}
6
1const number = (Math.random() - 2.5) * 5;
2if (number < 0) {
3 console.log('Number is negative');
4}
5if (number = 0) {
6 console.log('Number is zero');
7}
8if (number > 0) {
9 console.log('Number is positive');
10}