| Viewed 47 times

how to If-else statement in javascript


how to If-else statement in javascript

1 Answer
Mikdam Qandeel
Answered
0

If you want to execute a specific statement if a specific condition is true, Then you have to use if-else statement.

Example:

function PorN(num) {
  if (num > 0) {
    return "Positive";
  } 
}

console.log(PorN(2));

Output:

Positive

You can execute another statement if the condition is false.

Example :

function PorN(num) {
  if (num > 0) {
    return "Positive";
  } else {
    return "Negative";
  }
}

console.log(PorN(-1));

Output:

Negative