If Else Statement in Javascript
Here are the implementation of if else statement in javascript language:
// Declare and initialize the variable num
let num = 10;
// Check if num is greater than 0
if (num > 0) {
// If num is greater than 0, print "Number is positive."
console.log("Number is positive.");
} else {
// If num is not greater than 0, print "Number is non-positive."
console.log("Number is non-positive.");
}
Output
Number is positive.
This if else statement checks if the variable `num` is greater than 0. If so, the function says “Numbers are good.”; Otherwise, it prints “Number is non-positive”.
If Else Statement in Programming
An if else statement in programming is a basic programming technique that allows you to make decisions based on certain conditions. It allows your program to execute different pieces of code depending on whether the specified condition evaluates to true or false. This capability is crucial in building dynamic and functional applications.
Table of Content
- Importance of If Else Statement
- Basic Syntax of If Else Statement
- If Else Statement in C
- If Else Statement in Java
- If Else Statement in Python
- If Else Statement in Javascript
Contact Us