xxxxxxxxxx
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");
}
xxxxxxxxxx
if (5 < 10) {
console.log("5 is less than 10");
} else {
console.log("5 is now bigger than 10")
}
xxxxxxxxxx
var x = 1;
if(x==1)
{
console.log("x equals to 1")
}
else
{
console.log("x is not equal to 1");
}
xxxxxxxxxx
if (condition) {
// statement
} else if(condition){
// statement
}else{
// statement
}
/*OR*/
condition ? statement(true) : statement(false) // Ternary operator
xxxxxxxxxx
const count = 20;
if (count === 0) {
console.log('There are no students');
} else if (count === 1) {
console.log('There is only one student');
} else {
console.log(`There are ${count} students`);
}
xxxxxxxxxx
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');
}
xxxxxxxxxx
if (a > 0) {
result = 'positive';
} else {
result = 'NOT positive';
}
xxxxxxxxxx
if( condition ) {
// ...
} else {
// ...
}
Code language: JavaScript (javascript)
xxxxxxxxxx
if (condition){
// if true then execute this -}
else{
// if statment is not true then execut this -
}