how to write if condition in js code example

Example 1: js if else

If - Else Statements
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}

Example 2: if else javascript

if (time < 10) {
  greeting = "Good morning";
} else if (time < 20) {
  greeting = "Good day";
} else {
  greeting = "Good evening";
}

Example 3: using if statements in javascript

if (expression) {
   Statement(s) to be executed if expression is true
} else {
   Statement(s) to be executed if expression is false
}

Example 4: 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 5: 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");
}