Iffi em JS
// This function will be invoked right away we don't have to call it
(function () {
console.log("This is an IIFE");
})();
pratham82
// This function will be invoked right away we don't have to call it
(function () {
console.log("This is an IIFE");
})();
if (condition1) {
// code to be executed if condition1 is true
} else if (condition2) {
// code to be executed if the condition1 is false and condition2 is true
} else {
// code to be executed if the condition1 is false and condition2 is false
}
if( condition ) {
// ...
} else {
// ...
}
Code language: JavaScript (javascript)
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`);
}
var price = 500;
var money = 100;
if (price > money) {
console.log("Not Enough");
} else {
console.log("Can Buy");
}
if ((age >= 14) && (age < 19)) { // logical condition
status = "Eligible."; // executed if condition is true
} else { // else block is optional
status = "Not eligible."; // executed if condition is false
}