javascript if operator code example

Example 1: javascript if statement

if (5 < 10) {
	console.log("5 is less than 10");
} else {
	console.log("5 is now bigger than 10")
}

Example 2: 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 3: 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");
}

Example 4: javascript if

if (32 == 32) {
	console.log('32 is equil to 32!');
}

Example 5: if javascript

if (a > 0) {
    result = 'positive';
  } else {
    result = 'NOT positive';
  }

Tags:

Cpp Example