1var age=20;
2if (age < 18) {
3 console.log("underage");
4} else {
5 console.log("let em in!");
6}
1if (condition1) {
2 // block of code to be executed if condition1 is true
3} else if (condition2) {
4 // block of code to be executed if the condition1 is false and condition2 is true
5} else {
6 // block of code to be executed if the condition1 is false and condition2 is false
7}
1if (condition1) {
2 // block of code to be executed if condition1 is true
3} else {
4 // block of code to be executed if the condition1 is false
5}
1/* Shorten if-else by ternary operator*/
2const go = "yes"
3let race = null
4
5race = go === "yes" ? 'Green Light' : 'Red Light';
6
1var price = 500;
2var money = 100;
3
4if (price > money) {
5 console.log("Not Enough");
6} else {
7 console.log("Can Buy");
8}