Check if number is positive or negative in JavaScript

In this tutorial, we will see a JavaScript program to check if the given input number is positive or negative.

JavaScript has a single data type that represents a Number, the number can be Integer or Float.

To determine if the given number is positive or negative, we can use the following function.

const checkPositivity = (num) => {
  if(num === 0){
    console.log("It is a zero");
  }else if (num < 0){
    console.log("It is a negative number");
  }else{
    console.log("It is a positive number");
  }
}

checkPositivity(0); // It is a zero
checkPositivity(1); // It is a positive number
checkPositivity(-1); // It is a negative number