if condition js code example
Example 1: javascript if else
var age=20;
if (age < 18) {
console.log("underage");
} else {
console.log("let em in!");
}
Example 2: javascript how to do if else
if (condition1) {
} else {
}
Example 3: else if javascript
if (condition1) {
} else if (condition2) {
} else {
}
Example 4: how to use if else statement in javascript
var condition = true;
if (condition == true) {
console.log('condition is true');
} else {
console.log('condition is not true');
}
Example 5: javascript if
const number = (Math.random() - 2.5) * 5;
if (number < 0) {
console.log('Number is negative');
}
if (number = 0) {
console.log('Number is zero');
}
if (number > 0) {
console.log('Number is positive');
}
Example 6: if statement javascript
const randomObject = 5;
if(randomObject < 2) {
console.log("The Random Object has a value more than 2");
}
else {
console.log("The Random Object has a value less than 2");
}