Search

Is the Number Less than or Equal to Zero?

  • Share this:

In JavaScript, you can determine if a number is less than or equal to zero by using a comparison operator. Here is an example of how you could do this:

let number = -5;

if (number <= 0) {
  console.log("The number is less than or equal to zero");
} else {
  console.log("The number is greater than zero");
}

This code will output "The number is less than or equal to zero" because the value of the `number` variable is `-5`, which is less than or equal to zero.

You can also use the `<=` operator to compare two numbers and see if one is less than or equal to the other. For example:

let number1 = -5;
let number2 = 10;

if (number1 <= number2) {
  console.log("Number 1 is less than or equal to number 2");
} else {
  console.log("Number 1 is greater than number 2");
}

This code will output "Number 1 is less than or equal to number 2" because `number1` is `-5` and `number2` is `10`, and `-5` is less than or equal to `10`.

Tags:

About author
I am a professional web developer. I love programming and coding, and reading books. I am the founder and CEO of StorialTech.